Solved

Re-writing Access Expression in to VB.Net

Posted on 2009-05-14
5
184 Views
Last Modified: 2012-05-07
Hi Everyone

I need to convert the following expression in to a VB.Net 2005 code to a  
If  
then
else
end if

I am not familiar with the Switch so I do not get why the "true" part is there

The expression is the control source of a text box in an access 2003 report.

I would like if some one can explain me what is the 'true' in the expression doing and the converted code

Thank you in advance
jguinard
=Switch(IsNull([ndSeqBlank]),"",nz([ndSeqBlank])<=100000,"T-" & [ndSeqBlank],True,"D-" & IIf([ndSeqBlank]<100000000000,"0","") & [ndSeqBlank])

Open in new window

0
Comment
Question by:George
  • 4
5 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24390180
Should be something like this:

Private Sub ThisIsSwitch()

    Dim ndSeqBlank As String

    If IsNothing(ndSeqBlank) Then

        Return ""

    ElseIf nz(ndSeqBlank) < 100000 Then

        Return "T-" & ndSeqBlank

    Else

        Return "D-" & IIf(Integer.Parse(ndSeqBlank) < 100000000000, "0", "") & ndSeqBlank

    End If
 
 

End Function
 

Public Function nz(ByVal s As String) As Integer

    ' do something '

    Return 500

End Function

Open in new window

0
 
LVL 39

Assisted Solution

by:abel
abel earned 500 total points
ID: 24390220
apologies, that first "End Function" must be an "End Sub" of course.
> I am not familiar with the Switch so I do not get why the "true" part is there

that is a "trick" in Access. If you have a Switch, then the order is Switch(condition, returnMe, condition, returnMe). To have a Switch return a default value when all conditions are false, you can add a last True, which is always true:

Switch(condi1, value, cond2, value, cond3, value, True, defaultValue)

> The expression is the control source of a text box in an access 2003 report

in the code above, replace the "Dim ndSeqBlank As String" for:

Dim ndSeqBlank As String = MyTextBox.Text
0
 
LVL 39

Assisted Solution

by:abel
abel earned 500 total points
ID: 24390261
On another note, the maximum value of an Integer is 2147483647. You can use a Long instead where I have an Integer. The max value of a long is 9,223,372,036,854,775,807, which is large enough to hold your value of 100000000000
0
 

Author Closing Comment

by:George
ID: 31581719
Thank you very much Abel! Now I got it clear
I selected as multiple solutions your answers because they complement eachother but all 500 goes anyway for you-Tx

0
 
LVL 39

Expert Comment

by:abel
ID: 24390478
(from grading comment)> Thank you very much Abel! Now I got it clear> I selected as multiple solutions your answers because they complement eachother
I know, and that's the right way to do it. Glad it helped.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now