Digital Paint Discussion Board
Digital Paint Community => Other Stuff => Topic started by: Apocalypse on July 19, 2008, 05:55:58 PM
-
I have been making a program I use this code
Option Explicit
Dim msg As String
Dim dlgdef As String
Dim Caption As String
Private Sub cmdOK_Click()
If txtusername.Text = Master Then
If txtpassword.Text = M4573r5hip Then
Load (frmAdmin.frm)
Else
msg = "Incorrect Password"
dlgdef = "vbOKOnly"
Caption = "Incorrect Password"
MsgBox(msg, dlgdef, caption)
End If
Else
msg = "Incorrect Username"
dlgdef = "VbOKOnly"
Caption = "Incorrect Username"
MsgBox(msg, dlgdef, caption)
End Sub
When I edit something on the lines opening the message boxes and click on something else or go to a different line I get the error
Compile Error:
Expected: =
Any idea why I get this error?
-
If M4573r5hip is a string, surround it in quotes.
If I recall correctly, vbOKOnly is a global constant, so you need to remove the quotes.
-
Changed them but I still get that error.
-
Changed them but I still get that error.
FREENODE MERCILESS NAZI MODE ACTIVE
Where's your book?
-
It might help if you told us what line the error is on.
-
I have been making a program I use this code
Option Explicit
Dim msg As String
Dim dlgdef As String
Dim Caption As String
Private Sub cmdOK_Click()
If txtusername.Text = Master Then
If txtpassword.Text = M4573r5hip Then
Load (frmAdmin.frm)
Else
msg = "Incorrect Password"
dlgdef = "vbOKOnly"
Caption = "Incorrect Password"
MsgBox(msg, dlgdef, caption)
End If
Else
msg = "Incorrect Username"
dlgdef = "VbOKOnly"
Caption = "Incorrect Username"
MsgBox(msg, dlgdef, caption)
End Sub
When I edit something on the lines opening the message boxes and click on something else or go to a different line I get the error
Compile Error:
Expected: =
Any idea why I get this error?
Your error is on the MsgBox lines.
Because you're using ( ) after msgbox you must have a return value.
Do either of these:
1: Remove the ( ) e.g.
MsgBox(msg, dlgdef, caption)
into
MsgBox msg, dlgdef, caption
2. Add a variable to return a value to.
dim dummy
dummy = MsgBox(msg, dlgdef, caption)
You also need the " " around M4573r5hip as already noted.
Oh and since this is on a form you can't use the name Caption for any of your variables since it's already a part of the form. (Window title)
edit:
As sk89q noted, vbOKOnly is a constant but not only do you need to remove the quotes but you should use the correct datatype for dlgdef which believe is integer, definitely not string. I might be a long but I doubt it.
-
Thanks Krizdo I was looking through my book and noticed the no brackets and I figured out the caption thing just had no time to post. Not the string though that will save me lots of speed in big projects.
Offtopic: VB6 is the worst packaged program ever :/
-
I have "Visual Basic 2.0 for Windows". It comes on 2 floppy disks.
-
I have Visual Basic 6.0 comes with like 7 different cds :/
-
VB just seems painful to work in. Seriously, why not C#? As far as I can tell it's almost exactly the same, but without hideously unreadable syntax.
-
I've actually never tried C# before I should give it a try.
-
I've actually never tried C# before I should give it a try.
Learning a .Net language is going to do you a lot better than VB6 if you plan to ever get serious about things. Especially C#, since the syntax itself is important to become familiar with early on, so that you can move to C/Java/all the other C-derived languages. I'm not personally much of a .Net fan (despite Mono, it's still locked to Windows pretty well), but it's pretty decent if you're going to use C#, and the API itself is plenty expansive. Don't bother with VB.Net; coming from VB6, you will just become very confused, since it has very little in common with VB6.
I personally feel that learning VB6 threw me off a year or two as far as learning. You can do pretty much anything you want with VB6, but you aren't going to actually learn much that will be useful outside of VB6 (the most I got out of it was network programming with the winsock OCX control).
Get a C# book or google for tutorials. This one looks pretty complete, while being somewhat brief (this may not be as good as a book, though):
http://www.csharp-station.com/Tutorial.aspx
Going over an entire book or tutorial now will save you a lot of trouble later.
-
Thanks greatly appreciated I have programmed a very small amount in C++ but I never made anything very big with it.