Re: subscript out of range
Try switching your array definitions around:
VB Code:
Dim names() As String
Dim intcount As Integer
intcount = 0
For Each prntr In Printers
If Mid(prntr.DeviceName, 3, 5) = "srver" Then
intcount = intcount + 1
'resize array to fit added data
ReDim Preserve names(2, intcount)
'add the full string to the array
names(1, intcount) = prntr.DeviceName
shortname = Right(prntr.DeviceName, 3)
'add the short string to the array
names(2, intcount) = shortname
'add the short name to the listbox
List1.AddItem names(intcount, 2)
End If
Next prntr
Re: subscript out of range
ok, that worked ...
but i dont understand why ???????
ty btw :)
Re: subscript out of range
I'm not sure myself - I don't understand the low-level stuff, but I guess it might have something to do with the way the memory is allocated for dynamic multi-dimensioned arrays..? Hopefully, someone cleverer than me will be able to tell you.
Re: subscript out of range
When you use Preserve, you can only resize the last dimension.
Re: subscript out of range
thank you both
much appreciated
Re: subscript out of range
Does this work, if you dim names() at the form level?
VB Code:
Option Explicit
Public prntr As Printer
Public tempstr As String
Public tempint As Integer
Public longname As String
Public shortname As String
Dim names() As String
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdSetDefault_Click()
SetDefault (List1.ListIndex + 1)
End Sub
Private Sub SetDefault(prndefault As String)
'[help]
MsgBox names(1, prndefault) & names(3, prndefault)
End Sub
Private Sub Form_Load()
Dim intcount As Integer
intcount = 0
For Each prntr In Printers
If Mid(prntr.DeviceName, 3, 5) = "WDC01" Then
intcount = intcount + 1
'resize array to fit added data
ReDim Preserve names(3, intcount)
'add the full string to the array
names(1, intcount) = prntr.DeviceName
shortname = Right(prntr.DeviceName, 3)
'add the short string to the array
names(2, intcount) = shortname
'add the port to the array
names(3, intcount) = ",winspool," & prntr.Port
'add the short name to the listbox
List1.AddItem names(2, intcount)
End If
Next prntr
End Sub
Or are you trying to access names from multiple forms.
If so, then you should "Public Names() as string" in a module.
Re: subscript out of range
OOPS!
Just saw this:
VB Code:
Private Sub SetDefault(prndefault As String)
'[help]
MsgBox names(1, prndefault) & names(3, prndefault)
End Sub
What kind of an array uses strings for indexes?
Re: subscript out of range
tbh, i didnt know you could do that ??? will try now tho
Re: subscript out of range
ta very much, worked a treat.
Re: subscript out of range
Quote:
Originally Posted by NotLKH
OOPS!
Just saw this:
VB Code:
Private Sub SetDefault(prndefault As String)
'[help]
MsgBox names(1, prndefault) & names(3, prndefault)
End Sub
What kind of an array uses strings for indexes?
erm ... *** have i done there??? ...
Re: subscript out of range
It might be working, but you're making your progie force a conversion, from string to numeric, probably slowing things down.
{And, more than likely, whatever is calling it is probably forcing a conversin from numeric to string, doubly slowing things down.}
Re: subscript out of range
Quote:
Originally Posted by NotLKH
It might be working, but you're making your progie force a conversion, from string to numeric, probably slowing things down.
{And, more than likely, whatever is calling it is probably forcing a conversin from numeric to string, doubly slowing things down.}
yer, it was a crummy oversight ... now fixed :)
Re: subscript out of range
Re: subscript out of range
jsyk,
at the form level,
Dim == Private
So, its not accesable between forms, its just seeable everywhere in its parent form.
"Public" is directly accessable on its parent form, but only accessable from other forms via:
ParentFormName.Varname
BUT, if you do a Public in a module, then your variable is directly accessable everywhere!
-Lou
Re: subscript out of range