Planetarion Forums

Planetarion Forums (https://pirate.planetarion.com/index.php)
-   Programming and Discussion (https://pirate.planetarion.com/forumdisplay.php?f=57)
-   -   text files and combo boxes in visual basic (https://pirate.planetarion.com/showthread.php?t=182221)

vampire_lestat 17 Dec 2004 12:48

text files and combo boxes in visual basic
 
Here's what i've got so far:
Code:

Open "filename here" For Input As #1
Input #1, combo1[1]
Input #1, combo1[2]
close #1

But a list seperator or end of statement is expected. What does it want me to do?

JetLinus 17 Dec 2004 17:03

Re: text files and combo boxes in visual basic
 
Ok, first of all, you didn't say what exactly you want to do. But it seems you want to fill Combo-Boxes from a Text-File.

Well, combo1[1] is nothing really, it only describes a combobox. You must say WHAT you want to do. I.e.

Code:

Input #1, tempString
combo1[1].addItem tempString

Or, use combo[1].List[0] or whatever. Mark a combobox on the form, press F1, and see what you can do with it...



Uh, and 2 obligatory tipps for good programming style:
Dont use "as #1". You usually go like this:
Code:

Dim FileNum as Integer
FileNum = FreeFile()

Open .... as FileNum

Input FileNum

Close FileNum


The other thing is, I personally found, that opening files for Binary usually works best, then plain-reading strings, and parsing them. But ok, you probably need to get used to it and make your own experience...

Structural Integrity 17 Dec 2004 17:13

Re: text files and combo boxes in visual basic
 
Square brackets in Basic? That's something I haven't seen yet.

Leshy 17 Dec 2004 18:15

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by Structural Integrity
Square brackets in Basic? That's something I haven't seen yet.

Arrays.

Structural Integrity 17 Dec 2004 19:11

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by Leshy
Arrays.

I index arrays with round brackets in VB. I'm not 100% sure though (I probably tried it because I'm used to C/C++) but I thought you can't index with square brackets.

vampire_lestat 17 Dec 2004 20:18

Re: text files and combo boxes in visual basic
 
arrays use square brackets.

and thanks for the help, it's working ok now.

Structural Integrity 17 Dec 2004 22:34

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by vampire_lestat
arrays use square brackets.

and thanks for the help, it's working ok now.

I shall change my heretic habit in VB at once.

JetLinus 18 Dec 2004 13:54

Re: text files and combo boxes in visual basic
 
Wowowo NO!!!

Sorry people, I CANNOT understand how I -- always in favour of VB -- got this wrong, after only 8 weeks of Java course (and arrays only since 1 week).

Just as SI said: IN VB, you gotta use () for arrays. [] won't do it in VB.

I tried it:
Code:

    Dim heya(1 To 100) As Integer ' DOES work
    dim heyo[1 to 100] as Integer ' does NOT work


Structural Integrity 18 Dec 2004 14:13

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by JetLinus
Wowowo NO!!!

Sorry people, I CANNOT understand how I -- always in favour of VB -- got this wrong, after only 8 weeks of Java course (and arrays only since 1 week).

Just as SI said: IN VB, you gotta use () for arrays. [] won't do it in VB.

I tried it:
Code:

    Dim heya(1 To 100) As Integer ' DOES work
    dim heyo[1 to 100] as Integer ' does NOT work


"I told you so" ;)

Leshy 18 Dec 2004 20:49

Re: text files and combo boxes in visual basic
 
Fair enough. It's been ages since I've done anything in VB :p

Caesar2 19 Dec 2004 11:43

Re: text files and combo boxes in visual basic
 
Iirc square brackets in VB are only used for variable names that normally are not allowed:
Code:

Dim [Spaces are bad!] As String

JetLinus 19 Dec 2004 19:17

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by Caesar2
Iirc square brackets in VB are only used for variable names that normally are not allowed:
Code:

Dim [Spaces are bad!] As String

Nope. Doesn't work.

Caesar2 21 Dec 2004 10:07

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by JetLinus
Nope. Doesn't work.

I see now that it only seems to work in vbscript, but anyway it is pointless.

vampire_lestat 23 Dec 2004 14:44

Re: text files and combo boxes in visual basic
 
just checked, you're right. Damn java and its corrupting square brackets.

vampire_lestat 24 Dec 2004 15:31

Re: text files and combo boxes in visual basic
 
another quick combobox question: how do I use the selected value?

Structural Integrity 24 Dec 2004 16:16

Re: text files and combo boxes in visual basic
 
combo.text I think
or was it combo.value ?

vampire_lestat 24 Dec 2004 16:17

Re: text files and combo boxes in visual basic
 
combo.text seems to work, cheers.

JetLinus 25 Dec 2004 03:18

Re: text files and combo boxes in visual basic
 
Usually it should behave like a "normal" listbox, PLUS it's got the additional text-property for combo style.

So, you'd get the selected value like this (out of my head):
Code:

combo1.List(combo1.ListIndex)
You should really just select a combobox on a form and press F1, and then see what it can do. Or get some basic / fundamental tutorial or guideline.

I'm almost tempted to say RTFM, but I since it's Christmas and not that bad, well...

vampire_lestat 29 Dec 2004 15:36

Re: text files and combo boxes in visual basic
 
whilst this thread is here, can someone tell me how to hand variables across from one form to another?

Structural Integrity 29 Dec 2004 18:34

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by vampire_lestat
whilst this thread is here, can someone tell me how to hand variables across from one form to another?

That's an interesting question, because I have been wondering that myself (I haven't tried it yet).
My guess is that you can set the global variables that are in the form module.
Like:
Code:

' Form module frmTest
dim VARIABLE as long

Code:

' somewhere else
dim FORM1 as frmTest

FORM1.VARIABLE = 11

That would be my guess, but I could be wrong ofcourse. Let me know if you figure out how.
Also, let me know if you know how to open multiple instances of the same form (the same form, opened multiple times at the same moment).

JetLinus 29 Dec 2004 19:40

Re: text files and combo boxes in visual basic
 
Well, I'm not quite sure if SI's method would work, as I'm afraid you cannot use "dim" in a form module, but have to use "private" instead -- i.e. no public variables there.

I myself would work with modules (.bas-files) anyway. And do all the stuff from there. Have a Sub Main() where the project starts (Project, Properties, Startup Method, -> Sub Main). Then in this sub, you load and show all your forms etc.
To "pass" variables from Form to Form you'd use a global variable, declared in your module.
But all the important and non-form-specific stuff happens inside that module then anyway.


How you create multiple instances of a form I don't know, but I can guess:
Create and desing a form, let's say frmMain.

And then somewhere, call
Code:

Dim MyForms(1 to 100) as Form
Set MyForm(1) = New frmMain ' or maybe put the New in the line above...
MyForm(1).Show

'or try to this
Dim MyForms(1 to 100) as New frmMain
MyForm(1).Show

I'm sure the VB help will provide more info on this (see programming concepts).

vampire_lestat 30 Dec 2004 12:06

Re: text files and combo boxes in visual basic
 
SI, found this:-

Procedure-level variables are created with a Dim statement placed right in the procedure where it's going to be used. The value of a procedure level variable cannot be accessed outside it's procedure. When the procedure finishes (End Sub or End Function), the variable is destroyed and memory allocated to the variable is released.

Module-level variables are created with a Private statement in the general declarations section of a Form or code module. The value of the module level variable is available to every procedure in that module. Memory allocated to the module-level variable is not destroyed until the module is Unloaded.

Global variables are created with a Public statement in the general declarations section of a Form or code module. The value of a Global variable is available to any procedure, in any Form or code module. Memory allocated to a Global variable is not released until your program shuts down.

vampire_lestat 30 Dec 2004 12:15

Re: text files and combo boxes in visual basic
 
also, i think that if you want to load a form many times, can't you just do

Code:

dim no_of_forms as integer
for x=1 to no_of_forms
    load FormNameHere
    FormNameHere.show
EndFor


vampire_lestat 30 Dec 2004 12:24

Re: text files and combo boxes in visual basic
 
another question: how do i make a table, without using excel or anything else like that?

JetLinus 30 Dec 2004 13:31

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by vampire_lestat
also, i think that if you want to load a form many times, can't you just do

Code:

dim no_of_forms as integer
for x=1 to no_of_forms
    load FormNameHere
    FormNameHere.show
EndFor


Doesn't that just load / show the SAME form multiple times? One would have to try this and see if you really have multiple instances then....


Quote:

Global variables are created with a Public statement in the general declarations section of a Form or code module. The value of a Global variable is available to any procedure, in any Form or code module. Memory allocated to a Global variable is not released until your program shuts down.
This is just WRONG!
There can't be a "Public" statement in the code of a form. Try it. Not allowed. Only in modules...


Quote:

Originally Posted by vampire_lestat
another question: how do i make a table, without using excel or anything else like that?

Well, without using anything, you'd either have to use a textbox and insert TABs / BLANKs manually. Or program your own table :-/

I'd recommend MS GridLine Control. It's an OCX and should be installed on every system nowadays anyway. Also it come with the Visual Basic runtimes.
Just have a look around at those MS Common Controls. "Project, Components..."

vampire_lestat 30 Dec 2004 14:54

Re: text files and combo boxes in visual basic
 
i tried the public in a form and it seems to work ok :p, thanks for the table thing

JetLinus 30 Dec 2004 17:01

Re: text files and combo boxes in visual basic
 
Ok ok I am quite sorry ^^

I tried it as well now, and public SEEMS to be allowed for varialbles and subs/functions, but NOT for constants or external functions (from dlls, using "declare", e.g. winAPI).
Also you cannot have public arrays or strings of fixed length in forms...

vampire_lestat 3 Jan 2005 15:29

Re: text files and combo boxes in visual basic
 
true, but if you want to move text or arrays then just use text files or binary files or whatever.

JetLinus 7 Jan 2005 19:14

Re: text files and combo boxes in visual basic
 
Quote:

Originally Posted by vampire_lestat
true, but if you want to move text or arrays then just use text files or binary files or whatever.

What?? You cannot be serious!!! Moving data from one form to another using FILES? The detour of HDD access?
That's really bad. You should never do that.
Or I got it wrong.

But even if it's for messages between foreign forms (i.e. of different apps), you could use DDE or Callbacks or Shared Memory.


All times are GMT +1. The time now is 02:10.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018