Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

saving values, for some items only

I have an IF snippet that I need some help in making some changes if possible.

if ((left(ID,2)="AR" OR left(ID,2)="WO" ) and len(String1) <= 0) then
    String1 = ""
elseif Len(String1) > 0 then
    udfString1 = String1
end if

So what I am trying to accomplish is the following:

If an item contains AR or WO and the string1 is empty then string1 can be saved empty.
If string1 has a value, then that value can be saved.

What I am not sure of, is what would happen if string1 has a value, but it contains AR or WO? would it be saved still? - which is fine - or will it be left blank?

I am not sure if I am reading the logic correctly.

You help is greatly appreciated.

Thank you.
0
metropia
Asked:
metropia
  • 4
  • 3
1 Solution
 
Kelvin McDanielSr. Developer/ConsultantCommented:
The way it currently reads, if String1 has anything in it then it will be saved "as-is" regardless of whether or not ID contains "AR" or "WO".
0
 
hnasrCommented:
You listed your vision to the logic. It may be false if you are not getting what you expect.
.
So list 4 values for ID and their relevant expected output.
0
 
Martin LissRetired ProgrammerCommented:
What azarc3 said is correct but it's not completely clear to me what you really want to say in that code.

I'm guessing that you want to set udfString1 to some value. In that case then take a look at this.

If Len(String1) = 0 ' it can never be less than o
    If Left(ID,2)="AR" Or Left(ID,2)="WO" Then
        ' String1 is empty and the first two characters of ID are AR or WO
        udfString1 = ""
    Else
        ' String1 is empty and the first two characters of ID are not AR or WO
        What do you want to do here?
    EndIf
Else
    ' String1 is not empty
    udfString1 = String1
EndIf

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Kelvin McDanielSr. Developer/ConsultantCommented:
Also, I'm not sure if the VB6 interpreter considers "" to be Len(String) > 0. It might, and I don't have VB6 to test this.

In VB.NET I check for this using String.IsNullOrEmpty() or String.IsNullOrWhiteSpace() depending on the version of I'm using.

So, just in case, you might want to ammend the second part of your if statement to be

elseif Len(String1) > 0 And Not String1 = "" then
0
 
Martin LissRetired ProgrammerCommented:
@azarc3: If a VB6 string has no data then it's length is zero so

Dim s As String

MsgBox Len(s) ' gives 0

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Thanks @MartinLiss!
0
 
Martin LissRetired ProgrammerCommented:
Is there anything more we can do for you?
0
 
Martin LissRetired ProgrammerCommented:
I'm glad I was able to help.

My profile contains links to some articles I've written that may interest you.
Marty - MVP 2009 to 2012
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now