Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 6th, 2003, 05:22 AM
nbl nbl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 4 nbl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Working with arrays

I want to maintain values in an array var like so:
1 "A","ew2","xyz"
2 "B","re3","ert"
3 "C","5ty","dfg"
4 "D","6yu","wer"

where
1,2,3,4 will be the index

I will search with a string that will match a value in the [A,B,C,D] field
If I was looking for C and it was found in the said Array field then the function should return "5ty" & "dfg". I also want to delete that particular row based on the same search field ie: [A,B,C,D]
so that the new array looks like this
1 "A","ew2","xyz"
2 "B","re3","ert"
3 "D","6yu","wer"

Any pointers on how this can be done in VB?


Note: The size of array will increase at runtime and cant be decieded at the start.


Thanks.
Comments on this post
JimmyGosling agrees!

Reply With Quote
  #2  
Old February 6th, 2003, 05:23 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
Would using a Dictionary object work? You would reference the Microsoft Scripting Runtime which is scrrun.dll. This is the same as a Perl associative array. Basically, given value A, return value B

Code:
Sub main()
    Dim x       As New Scripting.Dictionary
    Dim z()     As String
    Dim key     As Variant
    
    x.Add "A", "ew2" & "|" & "xyz"
    x.Add "B", "re3" & "|" & "ert"
    x.Add "C", "5ty" & "|" & "dfg"
    x.Add "D", "6yu" & "|" & "wer"
    
    z = Split(x("C"), "|")
    MsgBox "1st C Value: " & z(0)
    MsgBox "2nd C Value: " & z(1)
    
    MsgBox "Array size: " & x.Count
    
    For Each key In x
        MsgBox key & " -> " & x(key)
    Next key
    
    x.Remove ("C")
    
    If x.Exists("C") Then
        MsgBox "C exists"
    Else
        MsgBox "C was removed from the dictionary"
    End If
End Sub

Reply With Quote
  #3  
Old February 6th, 2003, 10:50 PM
nbl nbl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 4 nbl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks dcaillouet for the response
Theres just one problem... the size of the array remains the same.... cant the Key "C" itself be removed so that the new array reads like this

1 "A","ew2","xyz"
2 "B","re3","ert"
3 "D","6yu","wer"

Reply With Quote
  #4  
Old February 6th, 2003, 11:44 PM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
The snippet of code I threw together was just to illustrate some of the methods and properties of the dictionary so you would be able to see how it worked.

This line of code removes the "C" element from the dictionary.
Code:
x.Remove ("C")
Theres just one problem... the size of the array remains the same....
No. If you run this code again at the end of the routine, you will see that the count is now 3 instead of 4 and that the "C" element is missing.
Code:
    MsgBox "Array size: " & x.Count
    
    For Each key In x
        MsgBox key & " -> " & x(key)
    Next key

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Working with arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway