Solved

Re-writing Access Expression in to VB.Net

Posted on 2009-05-14
5
185 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

27 Experts available now in Live!

Get 1:1 Help Now