• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Programming question

Techno

Golden Member
Hello,

I have a program that reads a file and then imports the data in this file to a sql server. The problem is, the file has spaces in certain fields.. like for example we have an account number that is DDA\827364556 yet in the file, sometimes it comes in as DDA \827364556 or in some cases it says DDA\827 364556. So the spaces can be just about anywhere and its only in this one field in the file. Never anywhere else. in Visual Basic 6, how can i get it to before sending the field to the table in the database, it looks for spaces and then deletes it and left justifies everything?

Thanks!
T.
 
off the top of my head....but isn't there a replace() function or something? like you'd do replace(original_string, string_you_want_to_search_for, string_to_replace_with)? then do something like replace(string, ' ', '')? I'm not sure on the syntax, though. heh i'm a lot of help, huh. I think the TRIM() function would get rid of any leading or trailing whitespace, too. msdn.microsoft.com is a good resource, too. good luck!

edit:
msdn's site apparently is crap now...i haven't done vb6 programming in awhile and i can't seem to find the right way to search for vb6 string functions. i did find this on google:

http://www.officecomputertraining.com/vbtutorial/tutpages/page19.asp

I think all you need to do, is something like TRIM(REPLACE(stringvar, " ", ""))

Note, in between the quotes is a single space, and then NO space. Good luck!
 
This is why 99% of developers dread visual basic 🙂

Any sort of string manipulation in VB is difficult ( or at least grossly inefficient ).

You can try iterating through each character in the string and then copying it over if and only if it's not a space. However I remember fighting with VB a few years back and I wouldn't figure how to access a specific character in a string without having to do something like right( length - offset -1, left( offset, string ) ).

Personally I'd never use VB in the first place, but I do recall it's easy to call another application from a VB app, you might want to write a simple perl script that will parse out the spaces and maybe even just pipe the output to the VB application as standard input.
 
Just like edmicman said. One line. No need to reinvent the wheel when VB's got you covered.

str = Replace(str," ", "")

 
Back
Top