?
Solved

Re-writing Access Expression in to VB.Net

Posted on 2009-05-14
5
Medium Priority
?
191 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 2000 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 2000 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

762 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