Results 1 to 5 of 5

Thread: If statement won't work

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    65

    Post

    Ok the I have a form which gets hidden and then another form loads and is supposed to determe what it does due to the values on the last form from a combo box plus an option box or what ever there called I'll give an example of the simple code I am trying to use:

    If Form3.Combo1.Text = "Ashenforest" + Form3.Option1.value = True Then
    Image1.Picture = LoadPicture("Ashen1.bmp")
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width
    End If

    If Form3.Combo1.Text = "Ashenforest" + Form3.Option2.value = True Then
    Image1.Picture = LoadPicture("Ashen1w.bmp")
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width
    End If

    If Form3.Combo1.Text = "Ashenforest" + Form3.Option3.value = True Then
    Image1.Picture = LoadPicture("Ashen1w.bmp")
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width
    End If

    now it won't load the picture for some reason, I know it something to do with the option part because when I took out the option part on one of them it worked fine... but I need it to determine which option has been picked.... anyone know what my problem is???

    thanx

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Change your "+" sings to "&". VB thinks you are trying to add something. Also your code would be slightly faster if you did the following. That way VB won't have to go through 3 If statements even if the 1st one happens to be true.

    Select Case True
    Case Form3.Combo1.Text = "Ashenforest" & Form3.Option1.value = True
    Image1.Picture = LoadPicture("Ashen1.bmp")
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width
    Case Form3.Combo1.Text = "Ashenforest" & Form3.Option2.value = True
    Image1.Picture = LoadPicture("Ashen1w.bmp")
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width


    Case Form3.Combo1.Text = "Ashenforest" & Form3.Option3.value = True
    Image1.Picture = LoadPicture("Ashen1w.bmp")
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width
    End Select



    ------------------
    Marty

  3. #3
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Hi, there. Actually you have to change + to And
    If Form3.Combo1.Text = "Ashenforest" AND Form3.Option1.value = True Then ...

    Larisa

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    LG is right! Boy am I embarrased

    ------------------
    Marty

  5. #5
    Lively Member
    Join Date
    Jul 1999
    Posts
    99

    Post

    Dim sBitmap as String

    With Form3
    If .Combo1.Text = "Ashenforest" Then

    ' Since only one option can be selected at a ' time it is safe to do this:

    If .Option1 Then sBitmap = "Ashen1.bmp"
    If .Option2 Then sBitmap = "Ashen1w.bmp"
    If .Option3 Then sBitmap = "Ashen1w.bmp"
    Image1.Picture = LoadPicture(sBitmap)
    Image1.Height = Screen.Height
    Image1.Width = Screen.Width

    End If
    End With

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