|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Compairson to a fixed length stringthen given it when defined. Dim FLS as String * 5 I have tried any number of means including If Trim(FLS) = VBNull ' it doesn't If FLS = String(5," ") ' it doesn't If FLS = String(5, VBNull) ' it doesn't If FLS = VBEmpty) ' nope If FLS=space(5) ' it doesn't If FLS =VBEmpty ' it doesn't I tried moving it to a non-fixed string Dim VLS as string Debug.Print Len(Trim(VLS) ' gives 5 I know there must be a simply way but I have not been able to determine it. Any assistance would be appreciated. Marv "Marv" <N*@columbus.rr.com> wrote in message '======news:%23XvCH3sVHHA.1200@TK2MSFTNGP04.phx.gbl... >I have a fixed length string that I am trying to see if it has any value >then given it when defined. > > Dim FLS as String * 5 > 'Fixed length strings are intialized to all Chr$(0)'s 'As soon as you use them though, they're padded with spaces. Private Sub Command1_Click() Dim FLS As String * 5 Debug.Print (FLS = String$(5, 0)) 'Shows True FLS = " " Debug.Print (FLS = String$(5, 32)) 'Shows True End Sub '====== -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. In Loving Memory - http://www.vbsight.com/Remembrance.htm Marv <N*@columbus.rr.com> wrote:
Show quoteHide quote > I have a fixed length string that I am trying to see if it has any value It's a string of nulls. Try this:> then given it when defined. > > Dim FLS as String * 5 > > I have tried any number of means including > > If Trim(FLS) = VBNull ' it doesn't > If FLS = String(5," ") ' it doesn't > If FLS = String(5, VBNull) ' it doesn't > If FLS = VBEmpty) ' nope > If FLS=space(5) ' it doesn't > If FLS =VBEmpty ' it doesn't > > I tried moving it to a non-fixed string > Dim VLS as string > Debug.Print Len(Trim(VLS) ' gives 5 > > I know there must be a simply way but I have not been able to determine it. > Any assistance would be appreciated. Dim FLS As String * 5 If FLS = String$(Len(FLS), 0) Then Debug.Print "ding ding ding!" End If Depending on your application, this may even be sufficient: If Asc(FLS) = 0 Then But that ignores all but the first char, beware. "Marv" <N*@columbus.rr.com> wrote in message If it has never been assigned then it's 5 nulls:news:%23XvCH3sVHHA.1200@TK2MSFTNGP04.phx.gbl > I have a fixed length string that I am trying to see if it has any > value then given it when defined. > > Dim FLS as String * 5 > > I have tried any number of means including If FLS=String$(5,0) Then If it has been assigned then it's spaces if FLS=Space$(5) Then best advice... don't use fixed-length strings except as part of a UDT for I/O -- Reply to the group so all can participate VB.Net: "Fool me once..." Actually, this was in connection with a UDT
Marv Show quoteHide quote "Bob Butler" <tiredofit@nospam.ever> wrote in message news:%23vDQP9sVHHA.4828@TK2MSFTNGP05.phx.gbl... > "Marv" <N*@columbus.rr.com> wrote in message > news:%23XvCH3sVHHA.1200@TK2MSFTNGP04.phx.gbl >> I have a fixed length string that I am trying to see if it has any >> value then given it when defined. >> >> Dim FLS as String * 5 >> >> I have tried any number of means including > > If it has never been assigned then it's 5 nulls: > > If FLS=String$(5,0) Then > > If it has been assigned then it's spaces > > if FLS=Space$(5) Then > > best advice... don't use fixed-length strings except as part of a UDT for > I/O > > > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > Thank you both
Marv Show quoteHide quote "Marv" <N*@columbus.rr.com> wrote in message news:%23XvCH3sVHHA.1200@TK2MSFTNGP04.phx.gbl... >I have a fixed length string that I am trying to see if it has any value >then given it when defined. > > Dim FLS as String * 5 > > I have tried any number of means including > > If Trim(FLS) = VBNull ' it doesn't > If FLS = String(5," ") ' it doesn't > If FLS = String(5, VBNull) ' it doesn't > If FLS = VBEmpty) ' nope > If FLS=space(5) ' it doesn't > If FLS =VBEmpty ' it doesn't > > I tried moving it to a non-fixed string > Dim VLS as string > Debug.Print Len(Trim(VLS) ' gives 5 > > I know there must be a simply way but I have not been able to determine > it. > Any assistance would be appreciated. > > Marv > > > > > Thank you both Just so you know, the methods outlined are not foolproof... it is possible for you to make this assignment FLS = Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) somewhere within you program... if you do so, then FLS will pass the tests provided. Unlikely, I know, but you should be aware of this possibility when using them. Rick |
|||||||||||||||||||||||