Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-04-2022, 03:12 AM
Bikram Bikram is offline Returning Boolean Windows 10 Returning Boolean Office 2007
Advanced Beginner
Returning Boolean
 
Join Date: Jul 2021
Location: Nepal
Posts: 97
Bikram is on a distinguished road
Default Returning Boolean


Greetings, I am trying to return boolean from a function but it is not returning its value. I know it is very simple but I have not been able why it is not returning value. Can anyone pointout what am i missing??
Code:
Sub autt()
Dim bln As Boolean, doc as document, i as integer,ii as integer
Set doc = ActiveDocument


    For i = 1 to Activedocument.range.paragraphs.count
    Set Para = doc.Paragraphs(i)
        If Selection.Information(wdWithInTable) = False Then
           bln = False
            Para.Range.Select
            
            

            bln = strr(bln)
            
            If bln = True Then                        'Here the boolean will be still be false even after assigning it to True in function
            If Not Left(Para.Range.Style, 1) = "1" Then
            If Para.Range.words(1) = Chr(9) Or Para.Range.words(2) = Chr(9) And bln = True Then
                Para.Range.Style = "tt"
            ElseIf Para.LeftIndent = 0 And Para.FirstLineIndent = 0 Then
                   Para.Range.Style = "t"
            End If
            If Para.Range.words(3) = Chr(9) Then
                    Para.Range.Style = "tt"
            End If
            End If
            End If
           
        Else
            ii = Selection.Tables(1).Range.Paragraphs.Count
            i = iparanum + ii
        End If
    Next

End Sub

Function strr(bln As Boolean) As Boolean
Dim x As Integer, rngg As String, y As Integer
rngg = Selection.Range.Text
x = Len(rngg): y = InStr(1, rngg, ":")
    If x - y < 3 And x - y >= 1 Then
        If Selection.Range.Text Like "*." & vbTab & "*" Then
            With Selection
                If .Paragraphs(1).Next.Range.Characters(1).Text = Chr(9) Then
                    .Paragraphs(1).Next.Range.Characters(1).Delete
                    .Range.Style = "tt"
                    .Range.Bold = True
                End If
            .Range.Characters(x).Delete
            .Range.Style = "tt"
            .Range.Bold = True
            bln = True                              'Here I have Set it to true the value in the main procedure is not turning to true
            End With
        End If
    End If
End Function
Reply With Quote
  #2  
Old 04-04-2022, 04:51 AM
Guessed's Avatar
Guessed Guessed is offline Returning Boolean Windows 10 Returning Boolean Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code has two different variables called bln - one in the sub, one in the function. If you defined bln once at the top of the module (above the sub) then it would exist at the module level and you would have only one bln and therefore could use and reassign it anywhere in the module.

Alternatively, you pass the variable's value back to the sub by changing the commented line in the function to...
Code:
strr = True
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 04-04-2022, 05:25 AM
Bikram Bikram is offline Returning Boolean Windows 10 Returning Boolean Office 2007
Advanced Beginner
Returning Boolean
 
Join Date: Jul 2021
Location: Nepal
Posts: 97
Bikram is on a distinguished road
Default

Thank you Andrew, I am very grateful for your reply. But when I declared module-level variable then while running the macro it said "Compile error" "By ref argument type mismatch" Can you please show the way to pass values correctly by modifying the code I posted. It would be of great help.
Reply With Quote
  #4  
Old 04-04-2022, 09:38 AM
Italophile Italophile is offline Returning Boolean Windows 11 Returning Boolean Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Code:
Sub autt()
    Dim bln As Boolean, doc As Document, i As Integer, ii As Integer
    Set doc = ActiveDocument

    For i = 1 To ActiveDocument.Range.Paragraphs.Count
        Set Para = doc.Paragraphs(i)
        If Selection.Information(wdWithInTable) = False Then
            Para.Range.Select

            bln = strr()
            
            If bln = True Then
                If Not Left(Para.Range.Style, 1) = "1" Then
                    If Para.Range.Words(1) = Chr(9) Or Para.Range.Words(2) = Chr(9) And bln = True Then
                        Para.Range.Style = "tt"
                    ElseIf Para.LeftIndent = 0 And Para.FirstLineIndent = 0 Then
                        Para.Range.Style = "t"
                    End If
                    If Para.Range.Words(3) = Chr(9) Then
                        Para.Range.Style = "tt"
                    End If
                End If
            End If
           
        Else
            ii = Selection.Tables(1).Range.Paragraphs.Count
            i = iparanum + ii
        End If
    Next

End Sub

Function strr() As Boolean
    Dim x As Integer, rngg As String, y As Integer
    strr = False
    rngg = Selection.Range.Text
    x = Len(rngg): y = InStr(1, rngg, ":")
    If x - y < 3 And x - y >= 1 Then
        If Selection.Range.Text Like "*." & vbTab & "*" Then
            With Selection
                If .Paragraphs(1).Next.Range.Characters(1).Text = Chr(9) Then
                    .Paragraphs(1).Next.Range.Characters(1).Delete
                    .Range.Style = "tt"
                    .Range.Bold = True
                End If
                .Range.Characters(x).Delete
                .Range.Style = "tt"
                .Range.Bold = True
                strr = True
            End With
        End If
    End If
End Function
Reply With Quote
  #5  
Old 04-04-2022, 07:39 PM
Bikram Bikram is offline Returning Boolean Windows 10 Returning Boolean Office 2007
Advanced Beginner
Returning Boolean
 
Join Date: Jul 2021
Location: Nepal
Posts: 97
Bikram is on a distinguished road
Default

Thank you Italophile for your effort..
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning Boolean Loop through Multiple Boolean Variables ScottyBee Word VBA 8 03-25-2019 03:24 PM
Formula returning zero allex011 Excel 2 12-03-2018 02:30 AM
Hard Returning Phil H Excel 2 05-15-2018 03:29 AM
Returning Boolean Returning a whole row kevskisa Excel 2 07-28-2015 03:19 AM
Returning Next Record to the top bordercollie10 Mail Merge 0 02-26-2009 09:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft