hello everybody

I am new to this forum. i got a doubt. i working on a small project. the thing is my Hosp no should be in the format 123456R. Now there are old patient with the following the hospital number 12345R. In this case i want a 0 to be added in the prefix. for 012345R. In both the cases I want R to be added automatically. Since an alphabet is a there i am using a text box but i don't know how to do a prefix or suffix

if right(ucase(text1.text), 1) <> "R" then
     text1.text = text1.text & "R"
else
     text1.text = "0" & text1.text
end if

...

Hi,

Check The Length and Prefix a 0

If Right(UCase(Text1.Text), 1) <> "R" then
    Text1.Text = Text1.Text & "R"
End If
If Len(Text1.Text)  < 7 Then
    Text1.Text = String((7-Len(Text1.Text)),"0") & Text1.Text
    'Pads with zeros to make 7 Chars 
End If

Regards
Veena

thanks for the post

hi qveen the syntax works fine for the first part, that is adding the "r"
but the problem with the second half is that it is not adding zero to the prefix but it is just making it zero

Hi,

Try This :

If Right(UCase(Text1.Text), 1) <> "R" then
      Text1.Text = Text1.Text & "R"
 End If
 Text1.Text = Right( "0000000" & Text1.Text,7)

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.