|
-
Dec 3rd, 2000, 10:40 PM
#1
Thread Starter
Member
ok this is the last time i'm gonna post this, I'm stuck and my prog will move no further until this is solved.
my program deals with the users selecting files from a listbox, and adding those selected into another listbox. From there, they are stored in a variable & numbered, and then finally outputted to a file. here is my theory of which i should be going about this:
file1.list (selections)>----->>> list2.list (selected)
(Bsp0 is the variable name I'd like to use)
file2.list >----->>> (Variable) Bsp0
Increment counter, thus >---->>> Bsp0 = Bsp0 + 1
Bsp0, Bsp1, Bsp2, ect are created to same number as list2.listcount
Generate A.WriteLine Bsp0, A.WriteLine Bsp1, ect at runtime to same number as list2.listcount
HELP! Someone tell me how to code this correctly!!! I have it down in my head butt... just can't spit out the code right.
If at first you DO succeed, don't look too astonished!
-deadBird
=================
-
Dec 4th, 2000, 05:10 AM
#2
Hyperactive Member
Are you not using an array?
-
Dec 4th, 2000, 05:29 AM
#3
The problem is you can't create a variable named X0, execute the X0 = X0 + 1 and expect to have a new X1 variable!!!!.
The solution is to use an array that has the same dimension as the number of selected elements:
Dim X(<num selections>)
For i = 0 TO <num selections> - 1
X(i) = ....
next i
Javier
-
Dec 4th, 2000, 03:17 PM
#4
Thread Starter
Member
The way you are specifing it, makes it jsut an array. The BsP's maximum value needs to be a variable!!! I believe I need to make it an dynamic array... an I don't know how to do that! Here's my code people, tell me what you can do!!!!!!!
Code:
Public Sub Command1_Click()
Dim GameType%
Dim BsP(1 To List2.ListCount) As String
For I = 0 To List2.ListCount - 1
BsP(I) = List2.List(0)
Next I
GameType = List1.ListIndex
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("doomanf.cfg")
a.WriteLine ("set m1 ""fraglimit 10" & " ; map ") & (Left$(BsP, Len(BsP) - 4))
a.WriteLine ("set m2 ""fraglimit 10" & " ; map ") & (Left$(Bsp1, Len(Bsp1) - 4))
ChDir (Spl1.Dir1.Path)
You see, I need those variables to be assigned from the user, to the writeline statements. File2.List(0) goes into the first a.WriteLine, and List2.List(1) goes into the second line. See? I'm trying to explain this as best I can.
If at first you DO succeed, don't look too astonished!
-deadBird
=================
-
Dec 4th, 2000, 03:41 PM
#5
Hyperactive Member
You declare a dynamic array like this
Code:
Dim BsP() As String
and then to change its values:
Code:
Redim Bsp(List2.ListCount)
Then do the rest of your code
-
Dec 4th, 2000, 03:47 PM
#6
Junior Member
maybe try Redim Preserve?
Why does BsP's maximum value needs to be a variable? You seem to be filling BsP with every list item in List2. So couldn't you just initially dimension BsP as:
Dim BsP(1 To List2.ListCount) As String
If you only going to say put List2's selected items into BsP you could try this method:
For i = 0 To List2.ListCount - 1
If List2.Selected(i) Then
ReDim Preserve BsP(iNum)
BsP(iNum) = List2.List(i)
iNum = iNum + 1
End If
Next
Then maybe:
For i = 0 to UBound(BsP)
a.WriteLine ("set m1 ""fraglimit 10" & " ; map ") & (Left$(BsP(i), Len(BsP(i)) - 4))
Next
-
Dec 4th, 2000, 04:44 PM
#7
Thread Starter
Member
ok, it wants a constant expression instead of
dim bsp(1 to list2.listcount)
the more I try, the more errors I get, how about i just send it to someone!? give me e-mail address so i can send them to ya and you people get a challenge!!!! This is really buggin me!! The source isn't that big, so voluteers post here.
What you need for it:
1) a file named quake3.exe in it's own folder
2) a subfolder name baseq3
3) another subfolder in baseq3 named maps (ie: baseq3\maps)
Thanks for the help.
If at first you DO succeed, don't look too astonished!
-deadBird
=================
-
Dec 4th, 2000, 05:02 PM
#8
Hyperactive Member
Why Use the Array BsP??
you can just use the data from the list box directly
Code:
For i = LBound(List2.List) to UBound(List2.List)
a.WriteLine ("set m1 ""fraglimit 10" & " ; map ") & (Left$(List2.List(i), Len(List2.List(i)) - 4))
Next i
-
Dec 4th, 2000, 09:36 PM
#9
Thread Starter
Member
Why use the array BsP? Well, because the List2.List argument is not optional. You must specify a ListIndex, perhaps you are on the right course... it seems that if you could modify that it would be useful.
4 down, x programmers to go!
If at first you DO succeed, don't look too astonished!
-deadBird
=================
-
Dec 5th, 2000, 01:11 PM
#10
Hyperactive Member
Have you tried using the dynamic array? Is that still your problem. I'm willing to have a look at your code.[email protected]
If you want to do it by yourself, redbird77's code should work if you change
Dim BsP(1 To List2.ListCount) As String
to
Code:
Dim BsP() As String
-
Dec 5th, 2000, 01:13 PM
#11
Just Playing...
I've been toying with your problem...
you can use the dim then redim to get around your problem
this just checks how many items are in the listbox...
then reads each line into the array...
Then prints to the debug window...
Code:
Public Sub Command1_Click()
Dim T() As Integer 'Dim
ReDim T(List2.ListCount) As Integer 'Then set the Amount (this way works)
For X = 0 To List2.ListCount - 1
List2.ListIndex = X
T(X) = List2.Text
Next X
For X = 0 To List2.ListCount - 1
Debug.Print "T(" & X & ") = " & T(X)
Next X
End Sub
this was a simple setup... but it alows the Array to be different lengths
I also noticed a few things in you code:
Code:
Public Sub Command1_Click()
Dim GameType%
Dim BsP(1 To List2.ListCount) As String ' dim 0 to listcount not 1
For I = 0 To List2.ListCount - 1 ' because here u start at 0
BsP(I) = List2.List(0) 'This sets every BsP(I) = to Item 0 in your Listbox (not sure if thats what you want)
Next I
GameType = List1.ListIndex
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("doomanf.cfg")
a.WriteLine ("set m1 ""fraglimit 10" & " ; map ") & (Left$(BsP, Len(BsP) - 4)) ' BsP is not an array here
a.WriteLine ("set m2 ""fraglimit 10" & " ; map ") & (Left$(Bsp1, Len(Bsp1) - 4)) ' or Here
ChDir (Spl1.Dir1.Path)
I am no expert but I hope I have helped somewhat...
maybe? Just a little? It would make me feel better If I did....I just want someone to like me!! 
Good luck

JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 5th, 2000, 03:43 PM
#12
Thread Starter
Member
All right! It actually outputted to a file!!! The only problem is, is that no matter how many a.WriteLine statements I have, the same thing is always printed in the output file. That would be the last list2.list item. Oh yeah, and one FINAL question, how do I get it to print as many a.WriteLines as in the list2.listcount? I don't want to have to put 30 A.WriteLine statements and therefore have a limit of only 30. See what I mean? Any worst of all, i think that this as well... MUST BE DONE DURING DESIGN-TIME! (i have less than no clue on this one)
I can't thank you all enough for all that you have done for me so-far!! Thank you!
Especially you geoff_xrx... you Fine Sexy thing you!
If at first you DO succeed, don't look too astonished!
-deadBird
=================
-
Dec 5th, 2000, 03:56 PM
#13
Gimme an Example...
Glad I could Help! 
Create a loop for the write line...
I can't quite understand what will be out put from the 1st section:
a.WriteLine ("set m1 ""fraglimit 10" & " ; map ") & (Left$(BsP, Len(BsP) - 4))
set m1 fraglimit 10 ; map ?
Give me an example of the new (fixed) writeline.
and what numbers will change for each new line.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 6th, 2000, 03:23 PM
#14
Thread Starter
Member
Well geoff... 
I'm glad you asked!
Well, you know how I have the WriteLine statment right? this is what is currently looks like:
Code:
On Error Resume Next
Dim GameType%
Dim BsP() As String
For i = 0 To List2.ListCount - 1
If List2.Selected(i) Then
ReDim Preserve BsP(inum)
BsP(inum) = List2.List(i)
inum = inum + 1
End If
Next
Dim T() As Integer 'Dim
ReDim T(List2.ListCount) As Integer 'Then set the Amount (this way works)
For X = 0 To List2.ListCount - 1
MsgBox "T(" & X & ") = " & T(X)
List2.ListIndex = X
T(X) = List2.Text
Next X
GameType = List1.ListIndex
'MsgBox "writing to doomanf.cfg"
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("doomanf.cfg")
For i = 0 To UBound(BsP)
a.WriteLine ("set m1 ""fraglimit 15" & " ; map ") & (Left$(BsP(i), Len(BsP(i)) - 4))
a.WriteLine ("set m2 ""fraglimit 15" & " ; map ") & (Left$(BsP(i), Len(BsP(i)) - 4))
Next
a.Close
As you can see, the code is functional, butt the only problem is, the list2.listcount is variable, which means that I will need to be printing multiple lines to the outpput file. This is what the output file looks like:
set m1 "fraglimit 15 ; map blammo3
set m2 "fraglimit 15 ; map blammo3
It only writes the last list selection as a result of every WriteLine statments, and I'm not really sure why. I have no idea about how to go about writing those lines that would normally be done at run-time. This is really kind of a hard question to ask!!! Well, as long as you're on the right track.
If at first you DO succeed, don't look too astonished!
-deadBird
=================
-
Dec 6th, 2000, 03:38 PM
#15
Hyperactive Member
Hey dead, you were extremely close! Here's the new command1_click. Things bold and underlined changed. I think this is what you want. It will output something like:
set m1 "fraglimit 15 ; map hello
set m2 "fraglimit 15 ; map someone
set m3 "fraglimit 15 ; map you
etc. (Well, that's the output I got)
Also you need to change your list1 multiselect to 1 or 2.(And then of course select more than 1 file before clicking command1)
Code:
Public Sub Command1_Click()
On Error Resume Next
Dim GameType%
Dim BsP() As String
For i = 0 To List2.ListCount - 1
If List2.Selected(i) Then
ReDim Preserve BsP(inum)
BsP(inum) = List2.List(i)
inum = inum + 1
End If
Next
Dim T() As Integer 'Dim
ReDim T(List2.ListCount - 1) As Integer 'Then set the Amount (this way works)
For X = 0 To List2.ListCount - 1
MsgBox "T(" & X & ") = " & T(X)
List2.ListIndex = X
T(X) = List2.Text
Next X
ChDir (Spl1.Dir1.Path) & ("\baseq3")
GameType = List1.ListIndex
MsgBox "writing to doomanf.cfg"
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("doomanf.cfg")
a.WriteLine ("")
a.WriteLine ("//This config file cycles through all the maps in the game. FFA mode.")
a.WriteLine ("")
a.WriteLine ("set g_gametype ") & (GameType)
a.WriteLine ("")
For i = 0 To UBound(BsP)
a.WriteLine ("set m" & i + 1 & " ""fraglimit 15" & " ; map ") & (Left$(BsP(i), Len(BsP(i)) - 4))
'a.WriteLine ("set m2 ""fraglimit 15" & " ; map ") & (Left$(BsP(i), Len(BsP(i)) - 4))
Next
a.Close
MsgBox "doomanf.cfg written successfully!!!"
ChDir (Spl1.Dir1.Path)
'Shell ("quake3.exe ") & (Dedicated) & (" +exec doomanf.cfg")
End Sub
BTW. Not a bad prog. Cool idea!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|