Clean up your code. Use ElseIf
.
Edward Giles
Posts
-
One button submit that handles the work with the database -
Redundancy at its finestIs the VB.NET equivalent of a float a
Double
(64-bit float) or aSingle
(32-bit float)? -
Redundancy at its finestI found this code in the My.Power extension for Visual Studio:
Public ReadOnly Property BatteryPercent()
' This code will retrieve the BatteryLifePercent property and convert it to a percent.
Get
If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
Return "100%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
Return "99%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
Return "98%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
Return "97%"
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
Return "96%"...
ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then Return "6%" ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then Return "5%" ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then Return "4%" ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then Return "3%" ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then Return "2%" ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then Return "1%" Else Return "NA" End If End Get End Property
What idiot would write this? How about:
If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
Return "NA"
Else
Return FormatNumber(SystemInformation.PowerSta -
Running out of Memory - Maths CheckTry doing the computation 1 pixel at a time, and discarding results from all the iterations except 0, n-1 and n, where n is the total number of iterations in the computation so far. This would reduce memory usage by complex numbers to just 48 bytes! EDIT: Probably not 48 bytes, but 3 complex numbers need to be stored. This could be any amount, depending on the precision used.
-
Converting a string into a methodIf the user is going to change large parts of the code, use a
ScriptControl
COM component. It allows you to run a String as code. -
Application with calendar menuSo it searches for files somewhere and places links to them into a calendar-like control(.NET
MonthCalendar
, perhaps?), so that the date the link is displayed on is the date of the last edit. At least that was what I understood it as. -
how change level?Open
yourformfile.designer.vb
and rearrange the initializing code, so that things that need to be displayed at the back come (in the code) before the things that need to be displayed further in front. P.S. I made a lot of assumptions. -
A Quine in VB.NETBecause I was bored.
-
ERROR_SUCCESS => the successful errorERROR_NOT_READY (Get a move on!) ERROR_CALL_NOT_IMPLEMENTED (Don't try to contact your friend with your laptop) ERROR_DISCARDED (you threw away your computer!) ERROR_PIPE_CONNECTED (That's an error?) ERROR_CANTREAD (Illiterate computer) ERROR_CANTWRITE (Ditto)
-
A Quine in VB.NETBulky but it works.
Sub Main()
Dim data = "Sub Main()End SubDim data = ""Console.Write(data.Substring(0, 10) & vbCrLf & data.Substring(17, 12) & data.Substring(0, 29) & Chr(34) & data.Substring(29) & Chr(34) & vbCrLf & data.Substring(29) & vbCrLf & data.Substring(10, 7))"
Console.Write(data.Substring(0, 10) & vbCrLf & data.Substring(17, 12) & data.Substring(0, 29) & Chr(34) & data.Substring(29) & Chr(34) & vbCrLf & data.Substring(29) & vbCrLf & data.Substring(10, 7))
End SubIt prints out the procedure declaration as well!
-
Aaaarg....use the namespace"VB (unfortunately) doesn't have this option (and please save me the C# vs. VB discussion)." It does have that option, at least in the version I've used (VB2010)
-
creating exeHere is the exact path where (project name) is the project name : %USERPROFILE%\Documents\Visual Studio 2010\Projects\(project name)\bin\debug\