Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

VB Help plz


rockbll4's Avatar
[TheN00bHacker]
0 0

Ok i'm making a program that randomly selects a picture from a directory and displays it into a picturebox. the pictures are picked at random That picture is a question. There is a textbox. i need to check the textbox to see if it contains the right answer to the picture. So i need to get the path of the picture so i can see if the answer goes with the picture Here is an example:

Randomize

num = int(rnd*18) + 1

picOut.Picture = LoadPicture(app.path & "\images\" & num & ".jpg"

If (picture location here) = app.path & "\images\1.jpg" And Answer = "hi" Then

MsgBox ("You got it right!"),,"Correct"

Else

MsgBox ("You got it wrong"),,"Wrong"

Endif


ghost's Avatar
0 0

There is a much easier way. Just make the answer an array, and have your code smiler to this:


num = int(rnd*18) + 1

picOut.Picture = LoadPicture(app.path & "\images\" & num & ".jpg"

**If answer = correctanswer(num) Then**

MsgBox ("You got it right!",,"Correct")

Else

MsgBox ("You got it wrong",,"Wrong")

Endif

I bolded the changed line. If you do it this way, you can use the same piece of code to check the answer for every picture, instead of needing to code a different one for all of them.


rockbll4's Avatar
[TheN00bHacker]
0 0

lol no, it doesnt work that way tho… heres part of the code:

 ' if its the element Hydrogen do this
    If (picture location here)  = App.path & "\images\1.jpg" then
    
        If txtSymbol.Text = ChemArr(1, 2) Then

            points = points + 2
            lblPoints = " " & points

        End If
    End If

 'if its the element Oxygen do this
   If (picture location here) = App.Path & "\images\1.jpg" then

       if txtSymbol.Text = ChemArr(2,2) Then

           points = points + 2
           lblPoints = " " & points

       End If

  End If

so i hope u kno why i need the path now :D and i hope u can help me with it this is for a chemistry assignment too… so i need it done :D


ghost's Avatar
0 0

J-Wreck gave you the best solution…

Here is an example code

Private Answers(1 To 18) As String

Private Sub Form_Load()
Answers(1) = "answer1"
Answers(2) = "answer2"
Answers(3) = "answer3"
' More answers goes here
NewPicture
End Sub

Private Sub Command1_Click()
If Text1.Text = Answer Then
MsgBox "Correct!"
' add points, ...
Else
MsgBox "Wrong!"
End If

NewPicture
End Sub

Private Sub NewPicture()
Randomize
Dim i As Integer
i = Round(Rnd * 17) + 1
Image1.Picture = LoadPicture(App.Path & "\images\" & i & ".jpg")
Answer = Answers(i)
End Sub```

I hope this will help you:)

rockbll4's Avatar
[TheN00bHacker]
0 0

lol wait i got it u guys :D thnx, i just thoguht of a better way to do something else on the program to :P