Results 1 to 9 of 9

Thread: IF statement problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    91

    IF statement problems

    VB Code:
    1. If strTemp2 = varAnimals Then
    2.         Image1.Picture = LoadPicture(App.Path & strTemp3)
    3.         Else
    4.         Image1.Picture = LoadPicture(App.Path & "\pics\not.jpg")
    5.         End If

    what I want the code to do is if strTemp2 = varAnimals then it displays the correct picture (strTemp3 is the pictures path that gets read from a txt file)
    or if there is no picture listed in the file to display not.jpg. It displays the not pic but does not display the ones that have pics...
    Patience with me Please! I'm Learning!

    Self Learning Newbie
    VB 6 Pro SP4

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Maybe there is white space in either of the variables so the if statemnet never is true??
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Make sure that both data types are strings.... varAnimals sounds like a variant, producing unreliable results.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Originally posted by techgnome
    Make sure that both data types are strings.... varAnimals sounds like a variant, producing unreliable results.
    Yes... use CStr(varAnimals) to make sure.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  5. #5
    Addicted Member aldinator's Avatar
    Join Date
    May 2002
    Location
    Canada - better than all the rest!
    Posts
    216
    i think its the line
    VB Code:
    1. Image1.Picture = LoadPicture(App.Path & strTemp3)
    it should be
    VB Code:
    1. Image1.Picture = LoadPicture(App.Path & "\" & strTemp3)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    91
    changed code to this

    VB Code:
    1. If strTemp2 = CStr(varAnimals) Then
    2.         Image1.Picture = LoadPicture(App.Path & strTemp3)
    3.         Else
    4.         Image1.Picture = LoadPicture(App.Path & "\pics\not.jpg")
    5.         End If

    the file it reads from is formated like

    AARDWOLF =\pics\aardwolf.jpg

    strTemp2 returns as AARDWOLF so does varAnimals (both look the same when I check them.)
    strTemp 3 returns as \pics\aardwolf.jpg

    Then not pic loads fine the listed pics do not


    [EDIT]
    After futher testing it is not going past the If Then line when I select an animal with a picture
    Last edited by spiritwolf; Nov 11th, 2002 at 12:22 PM.
    Patience with me Please! I'm Learning!

    Self Learning Newbie
    VB 6 Pro SP4

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    91
    Ok so for some reason that wasn't working so what I did was set Image1.Picture to "\pics\not.jpg" then used

    VB Code:
    1. Select Case varAnimals
    2.           Case strTemp2
    3.          Image1.Picture = LoadPicture(App.Path & strTemp3)
    4.         End Select

    And this works
    Patience with me Please! I'm Learning!

    Self Learning Newbie
    VB 6 Pro SP4

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    hrrmmm...... the only thing I can think of is:
    "A" <> "a" ... so "AARDVARK" <> "Aardvark"

    But..... the SELECT CASE isn't case sensitive....... ????
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    91
    Yes it is but everything was already set up for upper case.
    Patience with me Please! I'm Learning!

    Self Learning Newbie
    VB 6 Pro SP4

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