quote:
Originally posted by dylan!
still doesnt work heres my complete code
Please read the links I've posted. Especially those to the online MSDN library. Also read them and
understand them. Study (and I mean really: study) the examples. Play with those by altering small stuff, learn from that...
Also, go to your local library and pick up a book like "VB for beginners", "Starting with VB" and the likes! This is no joke!
RED = errors
GREEN = corrected or added code
ITALIC = Look up these terms in the help files (eg: msdn library), look them up on VB sites and read about them in books. Study them! and understand what they are, involve, the possebilities are, when they are used, why they are used, etc...
-------------------------------------------------------------------------------
code:
Dim intMsg, Message As String
Your first line is already faulty!
1) For each
variable you
declare you need to specify the
data type. If you don't do this, the variable will be declared as type
variant, which is very slow and prone to errors.
2) If you intended to declare intMsg as a
string data type (because you put it on the same line?) then that's wrong. intMsg should be a
numerical data type as it will recieve the return code from the messagebox.
Correct would be:
code:
Dim intMsg as Integer, Message as String
or
code:
Dim intMsg as Integer
Dim Message as String
Also, understand why you put those variables outside of any procedure and what the implications of that are!!! This is extremely important to understand!!!
----------------------------------------
code:
Private Sub Command2_Click()
Dim Pass As String
Open "C:\Program Files\Multi-app\password.txt" For Input As #1
Line Input #1, Pass
Where is your Pass variable declared? ALWAYS declare variables before using them or they will be declared as the data type
variant!! To avoid such errors put "
Option Explicit" on top of each
module,
form,
class, whatever...
----------------------------------------
code:
MsgBox (Pass & " is your Password.")
1) Why do you use parenthesis? Understand the reason why you can leave them out here. In fact, you should leave them out here as they, in this context, do not mean "put parenthesis around my used variables when I call this function" because you don't call
MsgBox as a
function but use it as a procedure/
sub.
The parenthesis in this particular context mean "group these instructions together and execute it first before the ones outside this group". Now, there is nothing outside it to execute. This will not result in an error but it will be left out automatically by VB when you compile your code because it is useless... Instead use
code:
MsgBox Pass & " is your Password."
or
code:
Call Msgbox(Pass & " is your Password.")
Study the difference between these two ways of
calling a sub (or a function as sub in this case). And study the difference between the use of parenthesis in the last one and with your code as there is a major difference because the parenthesis have yet another total different use there.
To illustrate this:
code:
FirstNumber = 8
SecondNumber = 7
Call DoSomeCalc(FirstNumber, (SecondNumber), 5 * (2 - 1))
All three pairs of parenthesis have three very different functions and do very different things!!!
1) Enclose all variables used to call a function or sub
2) Pass a variable by value instead of by reference
3) Alter the order of executing instructions in an instruction set
----------------------------------------
code:
Private Sub Command3_Click()
Open "C:\Program Files\Multi-app\password.txt" For Append As #1
If you would have read the links I posted to the official help documents of
Open,
Close, etc you would know why
append is not the correct choice here. Append will open the file for appending data to it. This means it will add data to the file, not replace it!! Since you, in Command2_Click(), read out the
first line of the file, the added passwords to that file will never be read out!
code:
Private Sub Command3_Click()
Open "C:\Program Files\Multi-app\password.txt" For Output As #1
Again, look up all this stuff and study why, how and when to use what.
----------------------------------------
code:
intMsg = MsgBox("Password Rememberer opened.")
Message = InputBox("Enter Password")
Print #1, intMsg; Message
1) Is there a reason why you also store the return code intMsg of the messagebox??? I don't think so, especially since you want to read out the password, and not the return code.
2) Is there even a reason to catch the return code? You don't do anything with it, so why assigning the return code to the variable intMsg in the first place?
3) Do you know what ";" means in this case? Look it up...
4) Do you know why you use "Print #1" here? What is the meaning of "#1"?
code:
MsgBox "Password Rememberer opened."
Message = InputBox("Enter Password")
Print #1, Message
----------------------------------------
code:
Private Sub Command1_Click()
Dim Pass As Integer
Why
integer???? An integer is a numerical data type. The
InputBox function returns a
string data type, not a numerical one.
code:
Private Sub Command1_Click()
Dim Pass As String
----------------------------------------
code:
Open App.Path & "C:\Program Files\Multi-app\password.txt" For Input As #1
1) What is "App.Path &" doing there??? Even if you don't know what it means, you surely would see that it will add something to the path string you already have and you hopefully would know "somethingblahblahc:\program files\myfile.txt" is not a valid path!
2)
App is an
object which contains lots of
properties and a few
methods. One if these properties is
Path. As you can read in the helpfiles and all over the net, it contains the application's path; In case you run your application in the debugger it contains the path to VB6.EXE. In case you compile your application it will contain the correct path of where your application (the exe) is stored.
3) About the "For Input". Why input??? You clearly ask for a password and then say "remembered" in the messagebox. Thus, logically and judging from that, you are saving the password. And thus you should open the file for
Output, use
Print #1 and don't forget to
Close the file after writing. In other words, this whole would be exactly the same as Command3_Click().
----------------------------------------
code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Are you sure you want to shut down?", vbYesNoCancel) <> vbYes Then
Cancel = True
End If
End Sub
Judging from your other code, shown above, I can guess that you didn't wrote this? If so, try to understand what it really does. eg:
-Why are the statements used like they are used
-Why using
MsgBox("something", vbYesNoCancel) suddenly? From where does ", vbYesNoCancel" part comes from? What does it mean?
-What is
vbYes? What data type is it?
-What is the exact use of
Cancel?
-Why do all this in the
QueryUnload event?
-What is an
event exactly?
-When does QueryUnload trigger exactly? Does it trigger more than once?
-What events proceed and follow the QueryUnload event by default?
----------------------------------------
code:
Private Sub mnuHelp_Click(Index As Integer)
Understand from where the "Index As Integer" comes from, how it got there, etc. (the answer is not "because VB6 put it there", as this is a direct result of something you did when designing the form)
-------------------------------------------------------------------------------
I will attach the completed corrected code. But this is for the last time since you realy need to start learning and studying all these things instead of copying and writing code you don't understand.
We can help with some real bugs or questions, but not with teaching someone how to program. We can not do your "homework" for you, you need to do that yourself; there are books for that and they are not for nothing hundreds of pages long. It is impossible to write a complete book here...
Sorry to say all this, but coming here with these kind of questions is not the right place to go. The correct place would be the library or at least the helpfiles which you constantly should use on every statement and piece of code you write to understand why you write it, how you write it and when you write it.
code:
Option Explicit
Private Sub Command2_Click()
Dim Pass As String
Open "C:\Program Files\Multi-app\password.txt" For Input As #1
Line Input #1, Pass
Close #1
MsgBox Pass & " is your Password."
End Sub
Private Sub Command3_Click()
Dim Pass As String
Pass = InputBox("Enter Password:")
Open "C:\Program Files\Multi-app\password.txt" For Output As #1
Print #1, Pass
Close #1
MsgBox "Password saved."
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("Sure?", vbYesNoCancel) <> vbYes Then
Cancel = True
End If
End Sub
Private Sub mnuHelp_Click(Index As Integer)
MsgBox "Mail me at here@blah.com"
End Sub
Public Function DoesFolderExist(ByVal strPath As String) As Boolean
DoesFolderExist = False
If Right$(strPath, 1) = "\" Then strPath = Left$(strPath, Len(strPath) - 1)
If Dir(strPath & "\nul", vbDirectory) = "nul" Then
DoesFolderExist = GetAttr(strPath) And vbDirectory
End If
End Function
Public Function DoesFileExist(strFile As String) As Boolean
If Dir(strFile & "\nul") = "nul" Then
DoesFileExist = (GetAttr(strFile) And (vbDirectory Or vbVolume)) = 0
End If
End Function
-------------------------------------------------------------------------------
Look up EVERY WORD that is part of the VB language in your code (aka every word which isn't made by you)!!! READ the entire explaination of it and STUDY the examples given about them in books and official help files and/or msdn library... This seems like a lot, but it is essential that you fully understand what each and every single command (yes, even symbols) means and does...
Learn to walk before you want to run...
-------------------------------------------------------------------------------
EDIT: I've also updated my first post in this thread with some important info concearning the DoesFolderExist() and DoesFileExist() routines... sorry for being so late with this, but I handn't the time earlier to write all that...
quote:
Originally posted by SonicSam
quote:
Originally posted by mad_onion
hmm this is all very interesting. im starting vb soon so i hope you will be able to help me with my coursework im making a roman numerals calculator (sounds easy) but i will probably need your help. i currently dont know any so it will be a steep learing curve
http://www.vb-helper.com/howto_calculator.html
which contains (obvious) bugs (as many of their sources do btw)