tags:

views:

19

answers:

1

i have an old string say oldString="abc-2" i want to change it to "abc-3" so i did this

myArray = Split(oldString, "-")
oldP = myArray(UBound(myArray))
myArray(UBound(myArray))= Str(val(oldP) + 1)
newString=join(myArray,"-")

why do I get the wrong number?? and if i try to use Cint(), then i got Error.

please help...

just found the real problem. I changed my input mode by accident and put a "Double-byte" number 2 into the same Field ,where i got my oldstring, of another Record. And after that CInt recognize my oldstring as wrong type. It seems that ms-Access changed the encode of that field implicitly, so that Cint do not know what to do and Val get the wrong value. They should have made Textfield in Access, String functions all encoding independent, or all use UTF-8. At least it should warn me when it change the encode of that textfield. Maybe i Should report it to MS?

A: 

If your joint function works well all should be fine. What you could try is this:

Open up VBA in Access and then open your Immediate window (View->Immediate window) Then execute these linese one by one and post your results.

oldString="abc-2"
myArray = Split(oldString, "-")
oldP = myArray(UBound(myArray))
?oldP

This should promt 2 as the answer to ?oldP

myArray(UBound(myArray))= Str(val(oldP) + 1) 
?myArray(1)

This should prompt 3

newString=joint(myArray,"-")
?newString

This should prompt "abc-3"

Sjuul Janssen
thanks a lot, Sjuul. I have tried your way. As i said, you got oldP equal "2", but Val(oldP) equal 0!!! I just found the real problem. It is very tricky.
gstar2002
Im happy it helped you. Could you "accept" the answer?
Sjuul Janssen
Hi, Sjuul it is actually not "the answer". But i can do that. Muss i have account here to accept the answer?
gstar2002
On the left of my answer you see a V if you click it, it becomes green. Thats all
Sjuul Janssen