+ Reply to Thread
Results 1 to 7 of 7

Looping variable or arrays for boolean?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    440

    Looping variable or arrays for boolean?

    Hi,

    I am not familiar with array, but i am looking for a way to declare variable thru my looping.

    Let's say example in Userform, I have 5 textbox.

    Textbox1
    Textbox2
    Textbox3
    Textbox4
    Textbox5

    And I want to do such as:

    Dim blntext1 As boolean
    Dim blntext2 As boolean
    Dim blntext3 As boolean
    Dim blntext4 As boolean
    Dim blntext5 As boolean
    Dim i As Long
    
    blntext1 = False
    blntext2 = False
    blntext3 = False
    blntext4 = False
    blntext5 = False
    
    For i = 1 to 5
    If Len(Me.controls("Textbox" & i)) > 0 Then
    blntext(i) = True 
    Next i
    I want to identify via looping the textbox and associate the boolean variable if the textbox contains data.

    Any help?

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: Looping variable or arrays for boolean?

    Hi Calvin,

    Your code worries me. If you declare those Textboxes as Boolean I'm not sure you can do a text function of Len() on them.

    Read:
    https://msdn.microsoft.com/en-us/library/ae382yt8.aspx

    I think of a Boolean data type as being a 0 or 1. Both have Length of 1. BUT I'm not sure you can treat them like a string of characters. Normally when you Dim a String it saves a spot in memory for that string and the first character or two are the length of the string. In Boolean you don't have that construct. Just a On/Off or Yes/No or True/False, no length.

    Have you tried to Dim your TextBoxes as Text and see what happens then?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    440

    Re: Looping variable or arrays for boolean?

    Hi,

    Indid not declare those textbox ads boolean but I want to associate a boolean variable if the lenght is over 0 for each textbox using a loop function.

    Thanks.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: Looping variable or arrays for boolean?

    In the code you list above the DIM statement and "declare them" mean the same thing.

    Try your code again after using
    Dim blntext1 As String
    Dim blntext2 As String
    Dim blntext3 As String
    Dim blntext4 As String
    Dim blntext5 As String

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    440

    Re: Looping variable or arrays for boolean?

    If I declare blntext to String, how can it be in boolean?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Looping variable or arrays for boolean?

    Try this.
    Dim blntext(1 To 5) As Boolean
    
    Dim i As Long
    
        For i = 1 to 5
            If Len(Me.controls("Textbox" & i)) > 0 Then
                blntext(i) = True 
            End If
        Next i
    If posting code please use code tags, see here.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Looping variable or arrays for boolean?

    Perhaps
    Function blnText(index As Long) As Boolean
        blnText = (0 < Len(Me.Controls("TextBox" & index).Text))
    End Function
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Trouble Looping Multiple Column Arrays
    By D.L. in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2012, 03:32 AM
  2. [SOLVED] Save a Boolean Variable and Recall Later
    By Ricker090 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-13-2012, 03:45 PM
  3. Looping arrays in VBA
    By berabus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2010, 09:33 AM
  4. Boolean variable initial state
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2009, 08:31 AM
  5. Passing Boolean Variable To A Function
    By Shama in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2008, 11:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1