i have a string and want to split it at the spaces so i used the following code from the microsoft site: -
Dim TestString As String = "apple pear banana "
-
Dim TestArray() As String = Split(TestString)
-
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
-
Dim LastNonEmpty As Integer = -1
-
For i As Integer = 0 To TestArray.Length - 1
-
If TestArray(i) <> "" Then
-
LastNonEmpty += 1
-
TestArray(LastNonEmpty) = TestArray(i)
-
End If
-
Next
-
ReDim Preserve TestArray(LastNonEmpty)
-
' TestArray now holds {"apple", "pear", "banana"}
-
i m using visual basic 6.0. the variables cudnt be initialized where they were difined so i manipulated the code as -
Dim TestString As String
-
TestString = "apple pear banana "
-
Dim TestArray() As String
-
TestArray() = Split(TestString)
-
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
-
Dim LastNonEmpty As Integer
-
Dim i As Integer
-
LastNonEmpty = -1
-
For i = 0 To TestArray.Length - 1 'THE ERROR LINE
-
If TestArray(i) <> "" Then
-
LastNonEmpty = LastNonEmpty + 1
-
TestArray(LastNonEmpty) = TestArray(i)
-
MsgBox TestArray(LastNonEmpty)
-
End If
-
Next
-
ReDim Preserve TestArray(LastNonEmpty)
-
' TestArray now holds {"apple", "pear", "banana"}
-
y does this happen?? and it still shows invalid wualifier for TestArray.Length..is there any other way to find the length so dat we cud run the loop ftill dat value only???? i did try len(TestArray) and GetLength(TestArray) but to no avail
6 2449
maybe that code is only for VB.net
because i try to run the code (from microsoft), with a bit changes by add a listbox (ListBox1) into the form:
Dim TestString As String = "apple pear banana "
Dim TestArray() As String = Split(TestString)
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
Dim LastNonEmpty As Integer = -1
For i As Integer = 0 To TestArray.Length - 1
If TestArray(i) <> "" Then
LastNonEmpty += 1
TestArray(LastNonEmpty) = TestArray(i)
ListBox1.items.add(TestArray(i))
End If
Next
ReDim Preserve TestArray(LastNonEmpty)
' TestArray now holds {"apple", "pear", "banana"}
it works
i have a string and want to split it at the spaces so i used the following code from the microsoft site: -
Dim TestString As String = "apple pear banana "
-
Dim TestArray() As String = Split(TestString)
-
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
-
Dim LastNonEmpty As Integer = -1
-
For i As Integer = 0 To TestArray.Length - 1
-
If TestArray(i) <> "" Then
-
LastNonEmpty += 1
-
TestArray(LastNonEmpty) = TestArray(i)
-
End If
-
Next
-
ReDim Preserve TestArray(LastNonEmpty)
-
' TestArray now holds {"apple", "pear", "banana"}
-
i m using visual basic 6.0. the variables cudnt be initialized where they were difined so i manipulated the code as -
Dim TestString As String
-
TestString = "apple pear banana "
-
Dim TestArray() As String
-
TestArray() = Split(TestString)
-
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
-
Dim LastNonEmpty As Integer
-
Dim i As Integer
-
LastNonEmpty = -1
-
For i = 0 To TestArray.Length - 1 'THE ERROR LINE
-
If TestArray(i) <> "" Then
-
LastNonEmpty = LastNonEmpty + 1
-
TestArray(LastNonEmpty) = TestArray(i)
-
MsgBox TestArray(LastNonEmpty)
-
End If
-
Next
-
ReDim Preserve TestArray(LastNonEmpty)
-
' TestArray now holds {"apple", "pear", "banana"}
-
y does this happen?? and it still shows invalid wualifier for TestArray.Length..is there any other way to find the length so dat we cud run the loop ftill dat value only???? i did try len(TestArray) and GetLength(TestArray) but to no avail
it is not working . i am working in vb 6.0 and i havent done vb.net so i cant comment on dat. the code is having same errors:
1) it shows TestArray as invalid qualifier
2)the variables cannot be iinitialized where they r defined
In VB6, an array doesn't have attributes like .Length - that's from other languages (like Java, or its close cousin, VB.Net). What you need to use is the Ubound() function.
thnks a lot ...can u tell me any place or link where we can search funtions by the job they do and not by their names???lest i wud have found ubound() myself
thnks a lot ...can u tell me any place or link where we can search funtions by the job they do and not by their names???lest i wud have found ubound() myself
I think the MSDN website has some such reference, but it might take a while to track down the right place to browse. There's a lot of information there.
Also, I've just tried a Google search on "vb functions by category" and there were a few hits that looked as though they might be relevant. I didn't take the time to look at more than one or two, though.
Perhaps we could start such a list here, in our Articles section. (And we could add info on how to achieve similar things in VB and VB.Net)
Keep in mind, a bit of creative searching will often find what you want. For example, if you were to search TheScripts for something like "VB ARRAY SIZE" you would probably find some relevant entries, but you may need to spend some time reading through the discussions.
I think the MSDN website has some such reference, but it might take a while to track down the right place to browse. There's a lot of information there.
Also, I've just tried a Google search on "vb functions by category" and there were a few hits that looked as though they might be relevant. I didn't take the time to look at more than one or two, though.
Perhaps we could start such a list here, in our Articles section. (And we could add info on how to achieve similar things in VB and VB.Net)
Keep in mind, a bit of creative searching will often find what you want. For example, if you were to search TheScripts for something like "VB ARRAY SIZE" you would probably find some relevant entries, but you may need to spend some time reading through the discussions.
thnks a lot for replying...,
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Java script Dude |
last post by:
Some programmers prefer to stay with native level data structures such
as string arrays instead of using Object based data structures such as
ArrayList.
From and efficiency point of view. Are...
|
by: Don Starr |
last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string
(including nul), or the size of a pointer?
For example, assuming a char is 1 byte and a char *...
|
by: Simon Schaap |
last post by:
Hello,
I have encountered a strange problem and I hope you can help me to
understand it. What I want to do is to pass an array of chars to a
function that will split it up (on every location where...
|
by: Chad Myers |
last post by:
I've been perf testing an application of mine and I've noticed that there
are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String
instances being created.
I've done some...
|
by: jortizclaver |
last post by:
Hi,
I'm about to develop a new framework for my corporative applications
and my first decision point is what kind of strings to use: std::string
or classical C char*.
Performance in my system...
|
by: greenflame |
last post by:
I want to make a function that does the following. I will call it
thefunc for short.
'||Char>>'
I tried the following
def thefunc(s):
s = "||" + s + ">>"
|
by: rohitpatel9999 |
last post by:
Hi
While developing any software, developer need to think about it's
possible enhancement for international usage and considering UNICODE.
I have read many nice articles/items in advanced C++...
|
by: jerry.upstatenyguy |
last post by:
I am really stuck on this. I am trying to write a string array
containing a "word" and a "definition" to a class called Entry.
Ultimately this will end up in another class called dictionary. No,...
|
by: SneakyElf |
last post by:
i am very green with c++ so i get stuck on very simple things
anyway, i need to write a program that would
read data from file (containing names of tv shows and their networks)
one line at a time...
|
by: shapper |
last post by:
Hello,
I have two arrays of strings, s1 and s2:
s1 = "london, lisbon, paris, newyork"
s2 = "lisbon, yellow, France"
s2 will have only one item included in s1.
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |