Question:
Visual basic 6.0: getting an value without looping?
?
2009-07-11 06:02:49 UTC
here is the thing.

I am building a certain word list, however, for my end purposes the list shall be too big to loop through, for getting the values using that word.

But that leaves me a problem, and as far as i know, there is only one way to do it efficient.

Remember PHP arrays? $arr['something']
In these arrays, you can input any string between ' instead just a number.

In visual basic 6.0 standardly this isn't possible.
Is there a way, to get the same effect like looping, without looping?
Or maybe is it possible to use the way arrays in PHP work, within visual basic? ( so array indexes can be set with string )
Four answers:
?
2009-07-11 18:46:05 UTC
If I understand correctly you want to extract data related to a word... Like "MyWord ,4,5,some data, blah blah" So when you enter Myword you extract the 4,5,somedata.....



There are a couple ways of doing this ....





The easiest way to do this in VB is to use a collection of a structure or a collection of CSV strings.



A collection is like an array except its index starts at 1 instead of zero and you can assign a key value. So you load the data into a collection item and assign the "word" as a key. You can then pull the data stored in the collection by using the key word





If you need to use arrays then you will used several arrays where each index value is related to a specific record. You will need to have the words loaded into an array in alphabetic order . This will allow you to use a binary search for a word. This will find the item in the array and its index position in the array. You then use the index to read related values in the other arrays.
Captain Mephisto
2009-07-11 07:47:06 UTC
To the best of my knowledge there is no built in way to do this. IndexOf is not part of VB6.



You can set up a helper array to reduce the number of entries you have to check. This array would give the starting position within your larger array for each letter of the alphabet. You could even make this two dimensional and track the first two letters of words to reduce the searching even more. I have some lists, although not very large, that I use with an activeX alphabet control I wrote (that has a list of the letters of the alphabet and numeric and other character buttons that you click and it then positions a list display to start with the first entry of the character you selected. I use such an array of starting points for each letter to speed up the display.



Later. Thought about it a little more. Are you using this so you can insert new entries into your list? And why not store your array in Access and then use Access from your VB program? Let me know some more about what you are doing if you are inclined to share.
Heather
2016-04-06 01:38:58 UTC
I think u hav so many boxes in ur window so to check whether a box is empty or not when u click the 'ok' button do one thing, in your ok button click event sub okbutton_click() if txt_cost.text<>"" //do these stuff else exit sub end if end sub this will do instead of a loop as the text box is always empty the loop always bring the alert
2009-07-11 06:23:09 UTC
I am not sure, but can you check for "Array.IndexOf" if that works.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...