Log in

View Full Version : Visual Basic


Fitzchivalry
30-08-2008, 09:41 PM
Anyone know some VB out there I have been working on a small program. I am still fairly new to VB atm any time I compile and send the program to someone else the external files don't seem to be added currently the code I am using is...


If resourcename = "Wood" Then
Image1.Picture = LoadPicture("C:\Documents and Settings\Kevin\Desktop\ika cal\pics\img_wood.jpg")

Flawless
30-08-2008, 09:54 PM
Why are you trying to get a file in your documents for the program?

Fitzchivalry
30-08-2008, 11:07 PM
I play a game called Ikariam so I thought it might be fun to make a small calculator for it....I haven't finished it totally yet so I know there's a few bugs in it but here's the codeing for it so far.

Option Explicit
'The main commands for the program
Dim resourcename As String
Dim i As Image
Dim totalhrs As Integer
Dim totalmins As Integer
Dim current02 As Long
Dim Combo2 As String
Dim amount02 As Long
Dim wood01 As Integer
Dim wine01 As Integer
Dim sulfur01 As Integer
Dim marble01 As Integer
Dim glass01 As Integer
Dim mill01 As Integer
Dim total As Single





Private Sub Command1_Click()


resourcename = InputBox("Enter What resource you are calculateing here", "Resource box")
mill01 = InputBox("How much does your mill make per hour?", "Mill production")
current02 = InputBox("How much do you have now?", "Current resources")
amount02 = InputBox("How much do you want?", "Resourses needed")
If resourcename = "Wood" Then
Image1.Picture = LoadPicture("C:\Documents and Settings\Kevin\Desktop\ika cal\pics\img_wood.jpg")
ElseIf resourcename = "Sulfur" Then
Image1.Picture = LoadPicture("C:\Documents and Settings\Kevin\Desktop\ika cal\pics\img_sulfur.JPG")
ElseIf resourcename = "Wine" Then
Image1.Picture = LoadPicture("C:\Documents and Settings\Kevin\Desktop\ika cal\pics\img_wine.JPG")
ElseIf resourcename = "Marble" Then
Image1.Picture = LoadPicture("C:\Documents and Settings\Kevin\Desktop\ika cal\pics\img_marble.JPG")
ElseIf Combo2 = "Crystal Glass" Then
Image1.Picture = LoadPicture("C:\Documents and Settings\Kevin\Desktop\ika cal\pics\img_glass.JPG")
End If



total = (amount02 - current02) / mill01
'debugging



'format total
totalhrs = Int(total)
totalmins = ((total - totalhrs) * 60)


lblRes.Caption = totalhrs & "hrs" & totalmins & "mins"
'If amount02 = 0 Then
' MsgBox ("Please enter the amount you want")
'Else: MsgBox ("Thank you your total will now be calculated")
'End If

End Sub



Private Sub Command3_Click()
Dim intUserResponse As Integer
intUserResponse = MsgBox("Do you want to exit?", 36, "Exit?")
Select Case intUserResponse
Case 6 'If the user clicks "Yes" then...
End 'Quit the program
Case 7 'If the user click on No....
Exit Sub 'Then Exit the sub, not the program.
End Select
End Sub

==============================================

The pictures are more to give the user something pretty to look at.

Kinshara
31-08-2008, 10:14 AM
Opening the files in that manner will not add them to a compiled binary; you need to add them as resources in the project to be able to ship it as a single executable.

http://msdn.microsoft.com/en-us/library/3bka19x4(VS.80).aspx should cover adding the images, and

http://msdn.microsoft.com/en-us/library/tkkf2x4f(VS.80).aspx should tell you how to use them once they've been added.

Can't provide more detail than that, I'm afraid... it's been about a decade since I last used VB.

Sloth
31-08-2008, 11:50 AM
it gets the external files from your documents folder(which doesnt exist on your friends pc), they don't get added to the compile.

try something like

If resourcename = "Wood" Then
Image1.Picture = LoadPicture(Application.ExecutablePath & "\img_wood.jpg")

and just copy/paste the pictures in the same folder as the executable (what kinshara said is a bit more practical and better though) :)

Fitzchivalry
31-08-2008, 02:05 PM
Thanks for the info.

Fitzchivalry
12-09-2008, 09:26 AM
Seems there was a fairly simple way after all.

Image1.Picture = LoadPicture("pics\img_wood.jpg")

Fitzchivalry
13-09-2008, 08:57 PM
If anyone gets time could use some ppl to test it out and suggest immprovements.

http://w13.easy-share.com/1701547491.html