Solved

# saving values, for some items only

Posted on 2012-09-17
135 Views
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
Question by:metropia

LVL 11

Expert Comment

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

LVL 30

Expert Comment

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

LVL 44

Accepted Solution

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
``````
0

LVL 11

Expert Comment

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

LVL 44

Expert Comment

@azarc3: If a VB6 string has no data then it's length is zero so

``````Dim s As String

MsgBox Len(s) ' gives 0
``````
0

LVL 11

Expert Comment

Thanks @MartinLiss!
0

LVL 44

Expert Comment

Is there anything more we can do for you?
0

LVL 44

Expert Comment

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…