Results 1 to 5 of 5

Thread: Variables, I think?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Chemainus,BC,Canada
    Posts
    7

    Post

    how might i make
    X = 1 thru 100
    so that it would check something like this
    bah1
    bah2
    bah3
    bah4
    bah5
    etc..
    so that i dont have to type in like 100 lines of code instead of just one or 2?
    any suggestions?
    thanks,
    Tobyn

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I'm not sure what you're asking, but if you want X to be in a Range of 1 to 100, then use the And Operator in you Conditions, eg.

    If X > 0 And X < 101 Then Msgbox "X is In the Range 1 To 100!"

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Chemainus,BC,Canada
    Posts
    7

    Post

    actually,
    i was looking at doing something like this

    Code:
    Dim CountClick As Integer
    Dim X As Variant
    
    Private Sub cmdOK_Click()
    X = 0 + Label1.Caption
    X = 1 Or "2" Or 3 Or 4 Or 5 Or 6 Or 7 Or 8 Or 9 Or 10
    Dim bLoggedin As Boolean
    
        If txtuser.Text = GetAllSettings(App.Title, "Setup") And txtpass.Text = GetSetting(App.Title, "Setup", "pass1") Then
                  bLoggedin = True
                  
               ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "user" & X) And txtpass.Text = GetSetting(App.Title, "Setup", "pass2" & X) Then
                       bLoggedin = True
            ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "User3") And txtpass.Text = GetSetting(App.Title, "Setup", "Pass3") Then
                bLoggedin = True
            ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "user4") And txtpass.Text = GetSetting(App.Title, "Setup", "pass4") Then
                bLoggedin = True
            ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "user5") And txtpass.Text = GetSetting(App.Title, "Setup", "pass5") Then
                bLoggedin = True
            ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "user6") And txtpass.Text = GetSetting(App.Title, "Setup", "pass6") Then
                bLoggedin = True
            ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "user7") And txtpass.Text = GetSetting(App.Title, "Setup", "pass7") Then
                bLoggedin = True
            ElseIf txtuser.Text = GetSetting(App.Title, "Setup", "user8") And txtpass.Text = GetSetting(App.Title, "Setup", "pass8") Then
                bLoggedin = True
            Else
                bLoggedin = False
               End If
    accepeted:
        MsgBox IIf(bLoggedin, "Login Successful", "Login Failed")
    
    End Sub
    
    
    Private Sub Command1_Click()
    CountClick = Label1.Caption + 1
    SaveSetting App.Title, "Setup", "User" & CountClick, Text1
    SaveSetting App.Title, "Setup", "Pass" & CountClick, Text2
    Label1.Caption = CountClick
    Label2.Caption = CountClick
    End Sub
    Private Sub exit_Click()
    SaveSetting App.Title, "setup", "User#", CountClick
    SaveSetting App.Title, "setup", "Pass#", CountClick
    End
    End Sub
    
    Private Sub Form_Load()
    
    Label1.Caption = GetSetting(App.Title, "setup", "User#")
    Label2.Caption = GetSetting(App.Title, "setup", "Pass#")
    End Sub
    i don't think this works right, there must be a way not to have to right 100 + lines of code
    thanks,
    Tobyn

  4. #4
    New Member
    Join Date
    Nov 1999
    Location
    IL
    Posts
    3

    Post

    Sounds like you want to make the variable 'X' equal to a range of numbers from 1 to 100. VB can't do that. You CAN do this by using code similar to this:

    For X = 1 to 100
    'Your code here
    Next X

    Within this X starts out equal to 1 and each time it goes through it'll be equal to the next value (1,2,3,etc).

    Hope this helps.

  5. #5
    New Member
    Join Date
    Nov 1999
    Location
    IL
    Posts
    3

    Post

    CORRECTION:

    VB CAN make a variable equal to a range of numbers if you write a specific function or (even better) make 'X' an OBJECT and assign it a RANGE property.


Posting Permissions

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



Click Here to Expand Forum to Full Width