Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Re-writing Access Expression in to VB.Net

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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…
Suggested Courses

618 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