Click here to Skip to main content
15,895,011 members

Response to: Translating characters in textbox from file.

Revision 1
Well there are better ways of doing this in virtually any language to be honest. I've had a couple of cracks at working out the logic but my whiteboard isn't big enough :-) This stuff looks as if it was translated from assembler (badly) ... even MSBasic could have been more structured.

The snippet you posted didn't appear to have any multi-character matches, but you could still try using a string array (you can use equality on strings of more than one character). For example the whole set of C1, C2, ..., C25 can be replaced with a string array e.g.
VB
Dim iLoop As Integer
For iLoop = 0 To 24
        C(iLoop) = fname.Substring(iLoop + 1, 1)
Next
(watch out for whether the array is 1 or 0 based!)
Then that whole If cpos = 2 Then loc = C2 etc can be replaced with
loc = C(cpos-1)

The whole "loop" around LB10 is truly, truly awful. Have a look at splitting the string out properly (e.g. see this link http://forums.devshed.com/visual-basic-programming-52/split-a-string-vb6t-422408.html[^]) Whatever you do, you may need to draw that abomination out on paper with a good old flow diagram to work out how to simplify it.

I would suggest your plan of attack should be ...
1.Pull as much as you can out into small functions and subs so you can get a better picture of the overall "flow". This is especially true of the file handling.

2. Get rid of the GOTO's ... there is absolutely no need for a goto in VB6 except for some error handling constructs - but if you port this to VB.net then you can use Try-Catch instead.

Overall I definitely recommend porting this across to .NET (vb.net or c# ... former might be easier to translate this mess first). At the very least the error-handling will be more structured (and robust) and the loop handling is very good.

Good luck!
Posted 16-Jul-13 12:17pm by CHill60.
Tags: