Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual 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 ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old August 23rd, 2004, 11:23 AM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Linking several combobox selection (not combo Arrays)

I want to link several combobox selections to find a specific series of values from a
CSV text file. Does anyone know how to do this?

Reply With Quote
  #2  
Old August 23rd, 2004, 11:44 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
Your question is too vague to be able to answer. Post some more clarification.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old August 23rd, 2004, 04:13 PM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Post

I have three comboboxes

combo1 - Street address
combo2 - street number
combo3 - Direction of street.
User makes selection in all three comboboxes
and this selects iterates through a CSV text file to find exact values
(selected from combobox).

I hope thats clear.

Reply With Quote
  #4  
Old August 24th, 2004, 02:32 AM
Mythomep Mythomep is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Zaandam, The Netherlands
Posts: 70 Mythomep User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 37 sec
Reputation Power: 4
Send a message via MSN to Mythomep
Cool

Hi,

A simple solution is to make a button, grab the selected text and loop through the CSV file searching for the values. Code is below, it has a very fast CSV interpreting piece of code.

Code:
'---------------------------------------------------------------------------------------
' Procedure : ParseCSV
' DateTime : 29-09-2003 10:35
' Author	: Donald Lessau (VBSpeed.com)
' Purpose : Parses a CSV input string
' Inputs	: sExpression: string with CSV text.
'			 asValues(): Array with CSV text split into it.
' Depends : None
' Revisions :
'
'---------------------------------------------------------------------------------------
Public Function ParseCSV(ByRef sExpression As String, ByRef asValues() As String) As Long
Const lAscSpace	 As Long = 32 ' Asc(" ")
Const lAscQuote	 As Long = 34 ' Asc("""")
Const lAscSeparator As Long = 44 ' Asc(","), comma
 
Const lValueNone	As Long = 0 ' states of the parser
Const lValuePlain As Long = 1
Const lValueQuoted As Long = 2
 
' BUFFERREDIM is ideally exactly the number of values in Expression (minus 1)
' so: if you know what to expect, fine-tune here
Const BUFFERREDIM As Long = 64
Dim ubValues		As Long
Dim cntValues	 As Long
 
Dim abExpression() As Byte
Dim lCharCode As Long
Dim posStart As Long
Dim posEnd As Long
Dim cntTrim As Long
Dim lState As Long
Dim i As Long
' ----------------------
On Error GoTo PROC_ERR
If LenB(sExpression) > 0 Then
 
	abExpression = sExpression		 ' to byte array
	ubValues = -1 + BUFFERREDIM
	ReDim Preserve asValues(ubValues) ' init array (Preserve is faster)
 
	For i = 0 To UBound(abExpression) Step 2
 
	 ' 1. unicode char has 16 bits, but 32 bit Longs process faster
	 ' 2. add lower and upper byte: ignoring the upper byte can lead to misinterpretations
	 lCharCode = abExpression(i) Or (&H100 * abExpression(i + 1))
 
	 Select Case lCharCode
 
	 Case lAscSpace
		If lState = lValuePlain Then
		 ' at non-quoted value: trim 2 unicode bytes for each space
		 cntTrim = cntTrim + 2
		End If
 
	 Case lAscSeparator
		If lState = lValueNone Then
		 ' ends zero-length value
		 If cntValues > ubValues Then
			ubValues = ubValues + BUFFERREDIM
			ReDim Preserve asValues(ubValues)
		 End If
		 asValues(cntValues) = ""
		 cntValues = cntValues + 1
		 posStart = i + 2
		ElseIf lState = lValuePlain Then
		 ' ends non-quoted value
		 lState = lValueNone
		 posEnd = i - cntTrim
		 If cntValues > ubValues Then
			ubValues = ubValues + BUFFERREDIM
			ReDim Preserve asValues(ubValues)
		 End If
		 asValues(cntValues) = MidB$(sExpression, posStart + 1, posEnd - posStart)
		 cntValues = cntValues + 1
		 posStart = i + 2
		 cntTrim = 0
		End If
 
	 Case lAscQuote
		If lState = lValueNone Then
		 ' starts quoted value
		 lState = lValueQuoted
		 ' trims the opening quote
		 posStart = i + 2
		ElseIf lState = lValueQuoted Then
		 ' ends quoted value, or is a quote within
		 lState = lValuePlain
		 ' trims the closing quote
		 cntTrim = 2
		End If
 
	 Case Else
		If lState = lValueNone Then
		 ' starts non-quoted value
		 lState = lValuePlain
		 posStart = i
		End If
		' reset trimming
		cntTrim = 0
 
	 End Select
 
	Next
 
	' remainder
	posEnd = i - cntTrim
	If cntValues <> ubValues Then
	 ReDim Preserve asValues(cntValues)
	End If
	asValues(cntValues) = MidB$(sExpression, posStart + 1, posEnd - posStart)
	ParseCSV = cntValues + 1
Else
	' (Expression = "")
	' return single-element array containing a zero-length string
	ReDim asValues(0)
	ParseCSV = 1
End If
PROC_ERR:
Select Case Err.Number
Case Is <> 0
	MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ParseCSV of Module modGeneral"
	Err.Clear
End Select
End Function


That is the code that parses a line of CSV into a array you can use. Put it in a module so you can access it from anywhere.

Code:
Private Sub cmdSelect_Click()
Dim sLine As String
Dim asInput() As String
Dim hInputFile As Long
Dim bFinished As Boolean
Dim sStreet As String
Dim sHouseNumber As String
Dim sStreetDirection As String
' ------------------------------
On Error GoTo PROC_ERR
'
' Grab the data we need to search.
'
sStreet = cboStreet.Text
sHouseNumber = cboHouseNumber.Text
sStreetDirection = cboStreetDirection.Text
 
'
' Open the file and loop through it to find the data.
'
Open "C:\Temp\InputData.csv" For Input As hInputFile
 
Do Until EOF(hInputFile) Or (bFinished)
	Line Input #hInputFile, sLine
 
	'
	' For sophisticated error handling, use a long value for the return
	' of the function. It contains the number of elements in the array.
	'
	Call ParseCSV(sLine, asInput)
 
	'
	' Check for the data in the array.
	'
	If (asInput(0) = sStreet) And (asInput(1) = sHouseNumber) And (asInput(2) = sStreetDirection) Then
	 '
	 ' You found it.
	 '
	 bFinished = True
	Else
	 '
	 ' You did not find it.
	 '
	 bFinished = False
	End If
Loop
 
PROC_EXIT:
'
' Clean up and exit gracefully.
'
If (hFile <> 0) Then
	Close hFile
End If
PROC_ERR:
Select Case Err.Number
Case Is <> 0
	MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSelect_Click of Form frmImport"
	Err.Clear
	Resume PROC_EXIT
End Select
End Sub


This code will open a CSV file and loop through its contents looking for the search data. The parsing of the CSV is done by the ParseCSV function. I did not include much error handling or checking of the format of the file. I leave that up to you. One comment on the loop though. Some of you might say that you can also use a Exit Do when you find the values you are looking for. I believe that any use of Exit and Goto is evidence of poor logic. It makes your code much more harder to read and follow. By using the technique of an exit condition, your code flows more natural and is less likely to go decruct. If you need hard data, using a exit do usually increases complexity by a multiplier of 2 when using McCabe metrics, and understanding goes from simple to moderate. Bad fix percentage also increases, but not that much.

I will go and hide in my cave again.

Grtz.©

M.

Reply With Quote
  #5  
Old August 24th, 2004, 10:32 AM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Hi,
Thanks Mythomep I will go and look at the code.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Linking several combobox selection (not combo 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


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





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