The Jedi Academy. THE Place for Jedi training.
Forums
Content
The Academy
Learn
Communicate
Personal


Forums | General Discussion
Visual Basic 6.0
Jun 22 2004 08:27pm

Bail Hope of Belouve
 - Student
Bail Hope of Belouve
Anyone know it?
Or fairly experienced with it?

You see, I'm writing a little program, and have stumbled across a problem...
Now don't give me that Microsoft s*cks nonsense (:P), because we all know Microsoft pretty much sucks:P
But I had to learn VB for school, so I'm using what I've learned:P

Anyway, the problem is the following
(if you happen to know something about it please help me out)

So, a multi-line message is written in a textfile.
I want my program to load up the textfile and enter all the data in a textbox.
But when I use the code:

Open "<file>" for Input as #1
Input #1, Text1
txtMessage.text = Text1
Close #1

It only shows the first line, and nothing else
and I can't figure out a way to solve this problem

anyone got an idea?

You would be helping me out sincerely

Thanks in advance!
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.

This post was edited by Bail Hope of Belouve on Jun 22 2004 08:34pm.

  Login and add your comment! Previous Comments >
Comments
Aug 10 2004 07:56pm

CharmeDoNe
 - Student
 CharmeDoNe

hehe i Know it and i used it for some time but dont know this one now:p was few years ago :p:D
_______________
~*Official JA Ninja*~
[ Padawan and lil bro to SmilyKrazy ]
[-= Judge me by my size do you =-]


Aug 10 2004 05:49pm

Fizz of Belouve
 - Student
 Fizz of Belouve

umm, for a string, there is a seperate function in basic, imho.

woah these were ages. just check the STRCAT or whatever it might be....

for a generic array, yes, you mustnt index out of the array, and you musnt delete the first one.

thats a huge problem in Basic, since you cannot use binary trees, or linked lists.

Bail, it doesnt matter in which way you "mark" the right one to be deleted. but if the array is sorted things are easier, yet, for an array of 20, this is just weird.

one workaround would be, that you make an array with 2 dimensions, one is a boolean, the other the actual data.
and with the boolean you can "mark" the data "good" or "bad".

thus, deleting is easily done by marking data as "bad".
of course, your processing routine will suffer performance, but in some situations this is ok.

_______________
One of the Belouve boys, founder of the mighty FiZZsters
Midbie council #20 - Fizz - #1933 - Jan '03 - Aug '04

"Renfield, you idiot!"


Aug 10 2004 05:03pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

Quote:
Deleting from an array would require moving all subsequent array members down one index.

Lets say I want to delete array index 10 from from an array with size 20:

Dim MyArray(20) As String
Dim I As Long

For I = 11 to 20

MyArray(I - 1) = MyArray(I)

Next I

ReDim Preserve MyArray(19)


You can generalize that to cover a chosen index. The easiest way to delete it from the file is to completely rewrite the file with the new array contents (VB is extremely fast at writing to a file so don't worry about speed.)


To delete one works, but it's never the right one

It seems to me (please correct me if I'm wrong) that you have to put an IF-clause there to check which Description is selected, then I must be (I + 1) to 1000
always one higher than the one you want to delete

so:
If cboDescription.Text = Description(I) Then
I = (I + 1) To 1000
Description(I-1) = Description(I)
End If

this code does not work correctly, since I get the 'subscript out of range' eror when trying to delete the first link.

but I can't figure this one out. For the love of me, I just can't.

Any help please?
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


This comment was edited by Bail Hope of Belouve on Aug 10 2004 05:06pm.

Aug 09 2004 08:03pm

Fizz of Belouve
 - Student
 Fizz of Belouve

"on error 53 gosub/goto bla bla bla"

:D
_______________
One of the Belouve boys, founder of the mighty FiZZsters
Midbie council #20 - Fizz - #1933 - Jan '03 - Aug '04

"Renfield, you idiot!"


Aug 09 2004 07:58pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

Hey, is there some kind of function to say that a file isn't found?

I tried googling for it, but didn't seem to find anything...

Something like EOF, but then to say the file isn't there?

I tried doing:
If File Not Found

it autocorrects to:
If Not File

But this reacts every time, even when the file is there
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


This comment was edited by Bail Hope of Belouve on Aug 09 2004 08:05pm.

Aug 03 2004 03:46am

n00b
 - Student
 n00b

Quote:
This should be an extremely helpful link:

http://www.juicystudio.com/tutorial/vb/network.asp


Yes, very nice, the TCP control could even be used to communicate to an IRC server. IRC servers send text messages via TCP for commands and chat text. All the client program needs to know is connect to the IRC server TCP and how to respond and initiate a conversation with the IRC server. Also, if you took it this far, don't forget an ident response is normally required by the server as well.
_______________
Gone but hopefully not forgotten...

Aug 03 2004 03:06am

(Jedi)Obi-JK
 - Student
 (Jedi)Obi-JK

I was gonna throw this out sooner. But you could do a file like so:

user1 user1_pass
user2 user2_pass

I used 8 spaces for a reason, its a tabstop :)

Im sure you can do something like this in VB

$name = foo;

while !eof ( end of file )
read in line 1 $col1 $col2
if $name == $col1 && $pass == $col2
match
else
goto nextline

If you can finding a way to encrypt the file is good.

Other than that Im pretty much a noob in this area.

_______________
Silent Bob (Kevin Smith): You know, there's a million fine looking women in the world, dude. But they don't all bring you lasagna at work. Most of 'em just cheat on you.

-Steve (Obi)


Aug 03 2004 12:50am

Charly
 - Student
 Charly

Now... to solve the username storage on the server problem.

Aug 03 2004 12:36am

Charly
 - Student
 Charly

You are a god :D Thanks so much!!! :D

Aug 02 2004 11:21pm

(Jedi)Obi-JK
 - Student
 (Jedi)Obi-JK

This should be an extremely helpful link:

http://www.juicystudio.com/tutorial/vb/network.asp
_______________
Silent Bob (Kevin Smith): You know, there's a million fine looking women in the world, dude. But they don't all bring you lasagna at work. Most of 'em just cheat on you.

-Steve (Obi)


Aug 02 2004 05:46pm

Charly
 - Student
 Charly

Bump. Help :D

Jul 31 2004 09:40pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

Question from Charly:

I've been writing the base code for a chat program in Visual Basic.. It's not setup to connect to anything yet but I need some help recording multiple usernames to a .txt and having the program run through the list and check if the specified name is there.

Quote:
Dim User As String
Dim Pass As String
If txtNewUserName.Text = "" Then
MsgBox "No User entered, please try again!", , "User"
txtNewUserName.SetFocus
SendKeys "{Home}+{End}"
Else
If txtNewPassword.Text = "" Then
MsgBox "No password entered, please try again!", , "Password"
txtNewPassword.SetFocus
SendKeys "{Home}+{End}"
Else
'Write new name and password to file and close document.
User$ = txtNewUserName.Text
Pass$ = txtNewPassword.Text
Open App.Path & "\User.txt" For Output As #1
Write #1, User$, Pass$
Close #1
Me.Hide
frmLogin.Show
End If
End If


That's my code for creating a new user name.

Quote:
Dim User As String, Pass As String
Open App.Path & "\User.txt" For Input As #1
Input #1, User$, Pass$
Close #1
If txtUserName.Text = User$ And txtPassword.Text = Pass$ Then
Me.Hide
Form1.Show
Else
MsgBox "Invalid UserName or Password, try again!", , "Login"
cmdOK.SetFocus
SendKeys "{Home}+{End}"
End If


This is the read and confirm code but it's currently only for one username. This is the code I will use for the client but I need to know how to make multiple so I can implement it on the server side of the program.

Thanks in advance for your help guys.
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


Jul 29 2004 02:00am

n00b
 - Student
 n00b

Deleting from an array would require moving all subsequent array members down one index.

Lets say I want to delete array index 10 from from an array with size 20:

Dim MyArray(20) As String
Dim I As Long

For I = 11 to 20

MyArray(I - 1) = MyArray(I)

Next I

ReDim Preserve MyArray(19)


You can generalize that to cover a chosen index. The easiest way to delete it from the file is to completely rewrite the file with the new array contents (VB is extremely fast at writing to a file so don't worry about speed.)

_______________
Gone but hopefully not forgotten...

Jul 27 2004 10:11pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

great to see I was almost right for once :D

okay

I'm totally stumped at this one...

I've got an array of Description and URL

Now, I was wondering if it would be possible to select and delete only one of those values (and with the corresponding URL)
and by 'delete' I mean it must disappear from the files as well...

Do you have any idea on how to do this?
Or a site that explains greatly

Any help will be appreciated, thanks! :D
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


Jul 27 2004 09:14pm

JamesF1
 - Student
 JamesF1

Quote:
Quote:
OMGosh, I ph34r your maths sk1ll5! :D


This is an all too common mistake that even the pros make...


I know that - I do a lot of programming myself - was just pulling your leg :)
_______________
Website

Jul 27 2004 05:20pm

n00b
 - Student
 n00b

Quote:
mmm, is there a way to empty a txtfile?
I thought using:
Open App.Path & "\test.txt" For Output As #lngFreeFile
Print #lngfreeFile, ""
Close lngFreeFile


You got it man, just take the Print statement out and it will create a zero byte file.

Open App.Path & "\test.txt" For Output As #lngFreeFile
--REMOVE THIS LINE--> Print #lngfreeFile, ""
Close lngFreeFile

_______________
Gone but hopefully not forgotten...

Jul 27 2004 02:00pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

Thank you:)

mmm, is there a way to empty a txtfile?
I thought using:
Open App.Path & "\test.txt" For Output As #lngFreeFile
Print #lngfreeFile, ""
Close lngFreeFile

But that not only empties the file, it also leaves a white line at the beginning...

Any other ways?
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


This comment was edited by Bail Hope of Belouve on Jul 27 2004 02:02pm.

Jul 27 2004 12:58am

n00b
 - Student
 n00b

Quote:
OMGosh, I ph34r your maths sk1ll5! :D


This is an all too common mistake that even the pros make. If you want a solid version of a For Loop that is immune to Subscript out of Range, have VB ask itself what the lower and upper bounds of the array are like so:

For I = LBound(MyArray) to UBound(MyArray) - 1

String1 = MyArray(I)
String2 = MyArray(I + 1)

Next I

Another useful trick is to dynamically allocate your array like so:

Dim MyArray(0) As Long
Dim I As Long

For I = 1 to 100

ReDim Preserve MyArray(UBound(MyArray) + 1)

MyArray(UBound(MyArray)) = 1

Next I


_______________
Gone but hopefully not forgotten...

Jul 27 2004 12:48am

n00b
 - Student
 n00b

Quote:
I've read (and I'm being told) that I should include vb6run.dll, but I can't find this one anywhere...

Where should it be?
and do I have to include it?
(another thing I'm worrying about... would this work on Linux or Mac as well?)


It should be in your windows/system32 folder. You should really distribute the DLL and any other OCX or DLL files you referenced in your project. All VB files go to the same place, system32. If you don't want to make a huge install program and you didn't use any other OCX or DLL besides vb6run.dll (which is mandatory), you could link people to the Microsoft site where they should download what is called the VB 6 Runtime. They could then just download a zip of your program and off they go.

VB6 programs run on Win95, 98, ME, NT 4, 2000, XP. Basically, anyone running a 32 bit version of Windows. I've never tried it, but Wine under Linux may run a VB6 program. I've never read anything about VB 6 programs and the Mac. If there is something, it would be an emulator.

_______________
Gone but hopefully not forgotten...

This comment was edited by n00b on Jul 27 2004 12:50am.

Jul 26 2004 08:03pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

when I don't include it, right?

So, would it work everywhere if I do include it?
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


Jul 26 2004 07:50pm

Fate
 - Student
 Fate

Bail: it will work on Xp and Win2000, mabye 98, not too sure
_______________
I must not fear . Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear . I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.
Gom gom gom gom gom!


Jul 26 2004 06:35pm

JamesF1
 - Student
 JamesF1

Quote:
When M is 1000, M + 1 is 1001


OMGosh, I ph34r your maths sk1ll5! :D
_______________
Website

Jul 26 2004 01:07pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

yes thank you :)

A quick question

If I would just compile my program into an .exe and put this file into a zip, would it work on other computers?
I've read (and I'm being told) that I should include vb6run.dll, but I can't find this one anywhere...

Where should it be?
and do I have to include it?
(another thing I'm worrying about... would this work on Linux or Mac as well?)
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


Jul 25 2004 10:16pm

n00b
 - Student
 n00b

The subscript out of range is the result of this:

Description(M + 1) = Response1

When M is 1000, M + 1 is 1001, which is probably one higher than the upper bound of the Description array. I'm only guessing that you have a line like this somewhere:

Dim Description(1000) As String

Make it 1001 and the code won't give you that error or lessen the upper bound of the For loop:

For M = 0 to 999

_______________
Gone but hopefully not forgotten...

Jul 23 2004 05:04pm

Bail Hope of Belouve
 - Student
 Bail Hope of Belouve

Quote:
Dim M As Integer
If Response1 = "" Or Response2 = "" Then
Exit Sub
Else
For M = 0 To 1000
If Description(M) = "" And URL(M) = "" Then
Description(M) = Response1
URL(M) = Response2
cboLinks.AddItem Response2
cboDescription.AddItem Response1
ElseIf Description(M) Like "*" And Description(M + 1) = "" And URL(M + 1) = "" Then
Description(M + 1) = Response1
URL(M + 1) = Response2
cboLinks.AddItem Response2
cboDescription.AddItem Response1
End If
Next M


Can anyone please say what's wrong with this code?

I want it to check which Array of M(variable for a number) is still available.
Thus the IF-clause.

The error I get is two-fold

First, if I have no M's, then it'll repeat M(1) a thousand times, which isn't the idea.
It only adds it a thousand times to cboDescription, but does not write it a thousand times to the file, so the mistake is somewhere above.

If I do have M's, then it'll give me the following error:
Subscript out of range

Anyone can help me?
_______________
Visit the Belouve Family Website!
Quote:
I try to have fun with my friends and try to make a difference as best I can. What does making a difference mean? Well, it can be as simple as saying hello, answering a question that seems obvious or heck, just talking. -- Vladarion

Want to know Vladarion? Read the Article about his life here.


This comment was edited by Bail Hope of Belouve on Jul 24 2004 01:39pm.

  Login and add your comment! Previous Comments >