What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Need VB help(Visual Basic)

Pages: (5): « First « 1 2 3 [ 4 ] 5 » Last »
Need VB help(Visual Basic)
Author: Message:
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: Need VB help(Visual Basic)
code:
Open App.Path & "C:\Program Files\Multi-app\password.txt" For Input As #1


Do you even KNOW what App.Path is? Surprise surprise, it's the path to the application. Why are you appending another path to the end?!

Why don't you re-read CookieRevised's post?

If you don't know a language you're never going to learn it by randomly copying/pasting code from other places hoping it'll work, and then asking other people to fix your code without an explanation of what was wrong. Buy a book. Follow some tutorials. Learn.

This post was edited on 09-11-2005 at 10:21 AM by segosa.
The previous sentence is false. The following sentence is true.
09-11-2005 10:12 AM
Profile PM Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: Need VB help(Visual Basic)
quote:
Originally posted by dylan!
Open App.Path & "C:\Program Files\Multi-app\password.txt"

I don't even know VB and I'm wondering why you're concatenating a full path with a full path.

Edit: not to mention forgetting to close it.

This post was edited on 09-11-2005 at 10:17 AM by ShawnZ.
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
09-11-2005 10:15 AM
Profile PM Web Find Quote Report
mad_onion
Full Member
***

Avatar
Windows Vista Rules!

Posts: 339
Reputation: 15
35 / Male / –
Joined: Jun 2004
RE: Need VB help(Visual Basic)
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 :)
[Image: vistasig9ys.jpg]
09-11-2005 09:01 PM
Profile E-Mail PM Web Find Quote Report
prashker
Veteran Member
*****


Posts: 5109
Reputation: 104
– / Male / –
Joined: Mar 2005
Status: Away
RE: Need VB help(Visual Basic)
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
09-11-2005 09:38 PM
Profile PM Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: RE: Need VB help(Visual Basic)
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 :)


2 years ago my A/S level computing task was a roman numerals calculator. Not doing Cambridge by any chance are you?
The previous sentence is false. The following sentence is true.
09-12-2005 06:48 AM
Profile PM Find Quote Report
mad_onion
Full Member
***

Avatar
Windows Vista Rules!

Posts: 339
Reputation: 15
35 / Male / –
Joined: Jun 2004
RE: Need VB help(Visual Basic)
lol yeah im doing ocr which is cambridge :) i cant believe they dont change the tasks lol :S
what did you get in the end and did you do it to A2 level?
[Image: vistasig9ys.jpg]
09-12-2005 06:15 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Need VB help(Visual Basic)
quote:
Originally posted by dylan!
still doesnt work heres my complete code 8-)

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)

This post was edited on 09-14-2005 at 04:26 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-14-2005 03:53 AM
Profile PM Find Quote Report
dylan!
Senior Member
****

Avatar
l33t p4int3r

Posts: 665
Reputation: 30
– / Male / Flag
Joined: Jan 2005
O.P. RE: Need VB help(Visual Basic)
hokay...i need some help...i have a thinger...and i have a filelist box thinger and i was wondering if when you clicked on a file in the filelist box thinger could it chnage the OLE to the selected file? and how?:S  and even more so if when you click on files on the OLE if it was a movie file or media file if it could play in a little wmp thinger? and how?:SOR even more so...when you click on a file in the filelistbox thinger it would play in the little wmp thinger? and how?:S

This post was edited on 10-09-2005 at 05:59 AM by dylan!.
10-09-2005 05:57 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Need VB help(Visual Basic)
Look at the various events available for the filelistbox...

eg:
File1_Click()
File1_KeyDown()
File1_KeyPress()
File1_PathChange()
File1_PatternChange()
etc...

Use the appropiate event for your cause and use the appropiate properties of the FileListBox to get the current selection. Handle it from there...
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-09-2005 01:14 PM
Profile PM Find Quote Report
dylan!
Senior Member
****

Avatar
l33t p4int3r

Posts: 665
Reputation: 30
– / Male / Flag
Joined: Jan 2005
O.P. RE: Need VB help(Visual Basic)
ok...ive looked but i still dont undertsnad this...there is nothing about what i need or want in my book...i need help with the code from getting the the selected in the filelistbox to play in wmp control??
10-09-2005 10:36 PM
Profile E-Mail PM Find Quote Report
Pages: (5): « First « 1 2 3 [ 4 ] 5 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On