Solved

Re-writing Access Expression in to VB.Net

Posted on 2009-05-14
5
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

737 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