.net - Vb .net Shorten An If Statement

Sep 29, 2011

I'm trying to make this cleaner... I know there's lots of shortcuts for If statements, but I don't know what's best.

If item.RecurrenceId > 0 Then
xmlTextWriter.WriteElementString("recordtype", "2")
ElseIf IsNothing(item.OngoingEndDate) = False Then
xmlTextWriter.WriteElementString("recordtype", "1")
Else
xmlTextWriter.WriteElementString("recordtype", "0")
End If

View 5 Replies


ADVERTISEMENT

C# - Shorten This If... Else... Statement To Check The State Of A Date?

Apr 2, 2010

I am a C# programmer but dabbling in VB.Net because everybody else in my team uses it. In the interests of professional development I would like to shrink the following If... Else... statement.

If cmd.Parameters("@whenUpdated").Equals(DBNull.Value) Then
item.WhenUpdated = Nothing
Else
item.WhenUpdated = cmd.Parameters("@whenUpdated").Value
End If

View 5 Replies

Is There Any Way That Can Shorten Code

Dec 20, 2011

This is the code that i would like shortenning, it uses a progress bar and a label that counts down with it: I'm using the language of VB..[code]

View 1 Replies

How To Shorten The Code

Mar 2, 2009

Is there a way to shorten the code below?

Like example:
from weeklbl1 to weeklbl4
location = new point ()

[code].....

View 2 Replies

.net - Shorten Array Declaration?

Sep 15, 2010

Question: How to shorten this array creation ? I need to create an array of type ReportingService2005_WebService.Property with one property.

Something like:

Dim PropertyArray() as new ReportingService2005_WebService.Property(1)

I have to do this:

Dim PropertyArray As ReportingService2005_WebService.Property() = New ReportingService2005_WebService.Property(0) {}
PropertyArray(0) = New ReportingService2005_WebService.Property

[Code].....

View 1 Replies

VS 2008 How To Shorten Long Value

May 4, 2012

Dim num as integer = 1.60285253
Msgbox(shorted num??)

I want msgbox to show only shorted version of that number, so It should give 1.06

And is is possible to make it round third number to higer? If I want limit it to 2 numbers only, it should show 1.06 as 1.1, but if number was 1.04 it shows shortened number as 1.0.

View 3 Replies

Any Algorithm To Shorten Very Large Integer?

Dec 8, 2010

I have a function which generates a very large Integer (I do this by using Biginteger from vjslib.dll and I am able to operate all kind of arithmetic operators on such a biginteger.) But, My goal is to shorten this big integer into a small integer. Is there any algorithm? or a mathematical Formula which I can use to represent it in a small integer and use some reverse formula to get the original Big integer?

The big integer my function creates goes like this:
98761210112313489375987956157462364864823458794572 34573485683465868234568613123749081377932457923457 93475897836587236458678234568234658362458762347895 68932456892346578636123846715376123475745723645666 38247687346128346812364812364816341384612384678345 76341236412783461278346781236481263489126348971238 41134681273467812364789

I do not want to represent my bigInteger in a higher base as it will not be possible to do conversion into higher bases with such a large integer.

View 2 Replies

Forms :: Shorten This Code Using A Wildcard?

Mar 8, 2010

I am making a project for school with visual basic and its a mcdonalds ordering system.There are 50+ buttons which you can press to remove an item and my code works fine. only problem is it is waaaaayyyy to long and can be shortened with a wildcard. Does anyone know what a good way to put a wildcard in the following code would be:

Private Sub btnsmallfries_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsmallfries.Click
If Label2.Text = "Buy Mode" Then

[code].....

View 5 Replies

Possible To Shorten Length Of Any Of String In A Way In Which It Also Can Be Reversed?

Jan 1, 2011

Im working a lot with normal strings and during my development process strings with lengts of 10.000+ characters are being processes which makes it a my application run slower.Is it possible to shorten the length of any of string, in a way in which it also can be reversed?

View 16 Replies

Replace / Shorten Word In RichTextBox

Feb 6, 2011

I am trying to use this code to shorten words like Hello to Hi, and Whats up to sup in a rich text box.
If Value.Contains("Hello") Then
Value.Replace("Hello", "Hi")
End If
End Sub

View 4 Replies

VS 2005 To Shorten This Line Of Code?

Mar 31, 2010

If xtn <> ".bmp" And xtn <> ".jpg" And xtn <> ".jpeg" And xtn <> ".png" And xtn <> ".gif" Then

I am getting a feel that there should an better way to do this

View 4 Replies

VS 2010 Unable To Shorten Code?

Jul 13, 2011

I want a textbox to be checked for specific characters. I can use: with textbox1.text If .contains("a") or .contains("b") or .contains("c")...etc... then...

View 7 Replies

Shorten Selected Value In ComboBox DropDown List For Display

Feb 21, 2010

I have a combo box that has a drop down list with long values in the drop down
Ex:

LB - Pounds
GR - Grams

When the user selects on of the values I want to just show the Abreviaqtions and not the descriptions. So when the drop down is shown it shows

LB - Pounds
GR - Grams

When the user selects "GR - Grams" from the drop down list "GR" is the only this shown in the combobox. I've tried TextChange,SelectedIndexChange and SelectedValueChange but I can't get them to work.

View 1 Replies

VS 2008 Shorten Code Adding Items Listview?

Feb 3, 2010

I have some code which addes values into the items and subitems, which works fine.

vb.net
Case "Aa en Hunze"
Dim Lvi00 As New ListViewItem(New String() {"naam", "blabla"})
Dim Lvi01 As New ListViewItem(New String() {"adres", "blabla"})
Dim Lvi02 As New ListViewItem(New String() {"postc/plaats", "blabla"})

[Code]...

View 4 Replies

Shorten This Code That Writes Current Year And Past Years?

May 26, 2011

<%
Dim i As Integer
Dim isNow = DatePart("yyyy", Now)

[code].....

View 1 Replies

Unable To Shorten It Before By Making A Generic Function To Create The Radio Buttons?

Oct 20, 2009

I'm sort of repeating the same steps. There's got to be a way to shorten it.I was able to shorten it before by making a generic function to create the radio buttons.This is the before the rewrite

Public Sub LoadPanels(ByVal tblClient As DataTable)
Dim count As Integer = 20
Dim tooltip As New ToolTip
Dim countName As Integer = 0

[Code]...

View 4 Replies

XML Shorten A "SelectNodes" List?

Nov 16, 2011

how I can shorten this and still get the same result (Wildcards maybe?)?

Dim NodeList As XmlNodeList
NodeList = NodeItem.SelectNodes("/Resultset/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group/Group[@name=""GroupPos""]/Field[@name=""S_TotalValue""]")

View 4 Replies

SQL Statement Doesn't Work - INSERT Statement Works Fine In The Form Load But Not In The Button Click Event?

Oct 14, 2009

See

Public Class Form1
Dim sql As String
Dim conn As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter

[CODE]...

The problem, The INSERT statement works fine in the form load but not in the button click event?

View 29 Replies

If <expression> Then <statement [:statement]> Else [statements] In Concrete Form?

Jan 1, 2010

I was convinced that If <expression> Then <statement [:statement]> Else [statements] in concrete form of If a = b Then SayHello() Else SayBye() End has sense. I read article on msdn on If-then-else, but I forgot why I was reading, so I concluded, that snippet above means this

If a = b Then HelloIsSaid : IsNotEnded Else ByeIsSaid : IsEnded But I have tested it now, and I see, that Else without statement is nothing more than decoration. It would be pretty good if it had function I described. Do you think its good request? Or do you know any circumstance where this Else has some function?

View 13 Replies

Making A Next Statement Into A Loop Statement In Visual Basic?

Jun 8, 2009

y friend and I are re-learning Visual Basic, and we are stumped on this bit of code.

For intAsterisks As Integer = 0 To intLine - 1
lblAsterisks.Text = lblAsterisks.Text + "*"
Next

View 6 Replies

Sql - Perform An Inline Select Statement In A LINQ Statement?

Jun 24, 2011

I have the following SQL:

[Code]...

I want to put it (the select count statement) in this LINQ statement so I can get the sales count in my linq statement: Dim TheLeads = (From L In DB.Leads Where L.IsDeleted = False Select L).ToList() Is this possible to do in LINQ?

View 1 Replies

Change The Exit Statement To A Continue Statement?

Feb 23, 2009

add an if statement and an exit statement to my do loop that exits when my future value (FV) is greater than 1000, then to change the exit statement to a continue statement so my loop will continue even though my fv is greater then 1000, point is to get this to run even though my if statement doesnt do anything. problem something wrong in my code and an exception error (xception of type 'System.OverflowException' occurred in mscorlib.dll)

so can someone show me where or why I have an error is, what am I overthinking now! I could use a hint, OMG i could use a tutor for that matter

[Code]...

View 3 Replies

ElseIf Statement Into A Select Case Statement?

Jun 23, 2010

A co-worker wants to convert the following IfThenElseIf statement into a Select Case statement.
Explain why this is not possible.

If temperature = 100 Then
X = 0
ElseIf population > 1000 Then
X = 1
ElseIf rate < .1 Then
X = -1
End If

View 7 Replies

SQL Statement :: Nearly Working Just Cant Get Form Values In Statement?

Aug 4, 2010

I cant get this SQL statement to insert any of the values in the form to add to the database

sql
sql = "INSERT INTO prevresults (ExamDate, ExamTime, CorrectAnswers, PassPercentage) VALUES (date.now, time.now, rightanswers, percentage.text)"

[code]....

View 4 Replies

Return Statement Which Is True In An If Statement?

May 24, 2012

Return statement which is true in an if statement

View 3 Replies

Break Up The Code In A Method Body Into Statement By Statement Symbols/"tokens"?

Apr 22, 2011

I'm writing something that will examine a function and rewrite that function in another language so basically if inside my function F1, i have this line of code var x=a.b(1) how do i break up the function body into symbols or "tokens"?I've searched around and thought that stuff in System.Reflection.MethodInfo.GetMethodBody would do the trick however that class doesn't seem to be able to have the capabilities to do what i want..dit 2:basically what I'm trying to do is to write a program in c#/vb and when i hit F5 a serializer function will (use reflection and) take the entire program (all the classes in that program) and serialize it into a single javascript file. of course javascript doesn't have the .net library so basically the C#/VB program will limit its use of classes to the .js library (which is a library written in c#/vb emulating the framework of javascript objects)

View 4 Replies

Exceptions - Can The "Throw" Statement Exist In A Block With No Try/catch Statement

Oct 5, 2009

how to use them then before, but am still a little confused with a few aspects. Here goes:

1.) Lets say you have a method that checks for a certain condition(s) and if it fails Throws an exception. Does it have to be in a try/catch block? Meaning can the "Throw" statement exist in a block with no try/catch statement?

2.) Now lets say we have a method that has a try catch block and in it there is a throw statement. When the throw statement is executed does it first try to find an appropriate catch block in the same method or does it immediately go back to the calling method without looking at the catch statements in the current method where the exception was thrown?

3.) I created a custom exception class that inherits from ApplicationException. Next I created a method which has a catch block that catches this type of exception and does some action. Is the System(i.e CLR) smart enough to throw an exception of this type, or does it only throw exceptions from SystemException?

4.) I know that some people are more liberal in their use of exceptions and others use it more sparingly when truly strange stuff happen like the DB going down. I am writing code where I am getting some info back from the database, converting it and then storing it. Sometimes there might be data that comes back from the database and other times the field is empty and the Null value comes back. Therefore in the instances where Null comes back from the database I should not convert the value to anything, since I will get an error. What should I do in this situation? Should I let the CLR throw the exception when it goes to convert the Null value or should I check for the Null value and if it exists not convert?

5.) In general when I throw exceptions, is it sensible to only throw exceptions of the type Application Exception or are there instances where the programmer throws exceptions of the type SystemException?

View 2 Replies

Make A 'like' Statement Or Use Some Kind Of Wildcard To Make The Statement Not Case Sensitive?

Jul 11, 2010

I'm building a listview search feature in my app. (See the code below). It works really well, except if you search "T" then the code removes all items, if you search "t" then it removes every item except for those starting with "t". Is there any way to make a 'like' statement, or use some kind of wildcard to make the statement not case sensitive?

For Each itm As ListViewItem In ListView2.Items
If itm.Text Like TextBox1.Text & "*" Or itm.SubItems.Item(1).Text Like TextBox1.Text & "*" Then
Else

[code].....

View 2 Replies

"End Of Statement Expected" Error In VB 2010 In A Do While Statement?

May 2, 2012

I have a line of code that is working in one statement but not the second statement. I'm not sure what I'm doing wrong, I am learning slowly but surely, and it is by no small margin because of the ave found here =) The error is occuring in the intResult = intSelection x intCount line of the SECOND Do While Loop.

The blue squiggle line is under "intCount" just FYI
Dim intSelection As Integer
Dim intCount As Integer = 0

[code]....

View 1 Replies

Components - "if" Statement Shows An Error " Statement Cannot Appear Outside Of A Method Body"

Jan 29, 2009

I have the following vb code which works as expected when it's in a code-behind page. I tried to move it to a shared or component page since I will need to use it in multiple pages:

Imports Microsoft.VisualBasic

Public
Class DetTime
'Determine eastern time

[CODE]...

However the "if" statement shows an error " statement cannot appear outside of a method body" and the Microsoft solution is to "move statement into a procedure or subroutine"

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved