VBA Parsing using Replace and Chr() (1 Viewer)

matthew

New member
Local time
Today, 02:11
Joined
Apr 25, 2012
Messages
3
I have begun my adventure into using and understanding VBA in Access with a simple task: Parsing a text string with carriage returns, semicolons, and several other characters.

I am using the Immediate window in Access 2010 as my test bed, in a manner similar to the irb (interactive ruby console) that Ruby uses.

I have written the following code:

<begin code snippet>

input_string="04.20.2012; Rx TO DOSE WARFARIN ; ORDERING MD= bubba, K ;
NOTES: 0n 2 mg daily ;
INDIC= A-FIB ; GOAL INR= 2-3 ; RPH=lv;
=======================================
04.20.2012 INR= 3.0; DOSE = 0 MG; RPH=zz
04.21.2012 INR= 1.9; DOSE = 1 MG; RPH=aa
04.22.2012 INR= 2.5; DOSE=2.5 MG ; RPH=bb
04.23.2012 INR= 2.3; DOSE=3 MG ; RPH=bbl
04.24.2012 INR=2.3 ; DOSE =4MG ; RPH=dd"
' functions
'0th Step
'cleans input_string
input_string=replace(input_string,Chr(10),"") 'removes new lines
input_string=replace(input_string,Chr(13),"") 'removes carriage returns
input_string=replace(input_string,Chr(59),"") 'removes semicolons
input_string=replace(input_string,Chr(61),"") 'removes equals signs
input_string=replace(input_string,Chr(45),"") 'removes minus signs
? input_string

<end code snippet>

I have tested bits and pieces of the string, and from what I have read in various forums, this should give me one long string with the specified characters removed, but when I enter the ? input_string command, the Immediate window just gives me a blank line.

I am not worried about DRY or style at this point, but rather just getting the hang of syntax.

Any help would be appreciated.

Thank you.
 

sparks80

Physicist
Local time
Today, 10:11
Joined
Mar 31, 2012
Messages
223
Hi,

If you want to enter a single statement over more than one line you can use the underscore symbol.

Another useful tip is that you can use the ampersand (&) symbol to concatenate two strings.

For example the following example:

Code:
input_string = "Some " & "text"

Will set input_string to "Some text"

The following example will give the same result:

Code:
input_string = "Some " & _
"text"
 

vbaInet

AWF VIP
Local time
Today, 10:11
Joined
Jan 22, 2010
Messages
26,374
The input_string variable is not declared as a PUBLIC variable in a Standard Module that's why you get a blank. Or are you setting the variable in the Immediate Window?
 

matthew

New member
Local time
Today, 02:11
Joined
Apr 25, 2012
Messages
3
@sparks80:Thanks...still getting a feel for VB syntax...worked perfectly

@vbaInet: I decided it was easier to develop in the module, and put any output in a msgbox to see if it was taken. Then all I had to do is run it and check the output that way.

Now that I have mastered this, I am moving on to parsing substrings and placing them into an array....wish me luck :)

As an aside, nice to not be ridiculed here..some forums are a bit more,er salty, to newbs...

Thank again...
 

Users who are viewing this thread

Top Bottom