Magic Number Vs Constant?

May 11, 2012

I save a lot of settings in an INI file as 1 (enabled) and 0 (disabled), all around the project's module i have this check If setting = 1 then ' do somethingEnd If ' OR If setting = 0 then ' do somethingEnd If

My question, is it good for performance to declare public constants to hold 1 & 0 and use them in such above checks instead of using real number?

In general, if i use value like 8, 9, "", "$", etc... in just two different places, should i declare constant for it?

View 16 Replies


ADVERTISEMENT

Forms :: Use A If Statement To See If Fosters Button And Number 1 On The Number Pad Are Both Pressed Then Multiply Constant By Quantity Number?

Mar 4, 2011

I am doing a bar cash register and I want to use a if statement to see if fosters button and number 1 on the number pad are both pressed then multiply constant by quantity number

View 1 Replies

Error When Unzipping File Using GZipStream(magic Number)

Jul 9, 2009

unzipping file using GZipStream.Heres the solution but i hope that i don't need to imports another dlls [URL] the zip files i compressed with 7z. and here the code...

[Code]...

View 8 Replies

Public Constant Versus Private Constant?

Aug 13, 2011

When building a class library which contains many classes, all classes uses a lot of common constants and functions, what is the best to do:

1- Declare these constants and functions as public in a module.

2- In each class declare constants and functions used by individual class as private.

The first choice is good for easy and fast implementation, but re-using a class in a different project will require importing the module to the other project.The second choice require a lot of copy/paste for code snippet but a class can be re-used in different project easily.

View 3 Replies

Late Binding Magic Under .NET Converted To C#?

Nov 22, 2011

I should convert some code from VB to C#. Given following lines of VB work (I think only because option is not set to strict):

Dim someProp As SomeType
Try
someProp = CType(SomeInstance, Object).SomeProp
' ...

Due to late binding, this code is possible under VB. Of course, following won't work under C#:

SomeType someProp;
try
{
someProp = ((object)SomeInstance).SomeProp;
// ...

How could I formulate something similar under C#?

View 1 Replies

Magic Numbers - File Header And Footer

Feb 12, 2011

For my project, I need to develop an app, which will have MS-SQL db with 4 tables
a>FileHeader
b>FileFooter
c>Extension
d>Detail about the file.
This is all to do with the Magic Numbers, or File header and footer, found in all files. The first 4-byte and last 4-bytes.

Example:
Suppose a word DOC file when read using this app should return and match the values
D0 CF 11 E0
So, how can I read the files using vb.net, fileIO, FileStream/StreamClass/FileReader? I just need to open the file and read the first 4 and last 4 bytes of any given file. And then it should connect back to the SQL database and lookup for the matching values from the tables as I had mentioned. And return a match found or not found.

View 5 Replies

VS 2008 - Writing A Driver For Magic Mouse In VB

Mar 7, 2010

I use the Magic Mouse, it's fantastic in OSX but more so because of MagicPrefs which extends the multi-touch gestures its capable of. I'd like to know if its possible for me to write drivers for the Magic Mouse in VB? to extend it's functionality. Or would this be better suited for C++? I don't even know where to start.

View 4 Replies

VS 2008 UDPclient.send Magic Packet (wol)

Jan 9, 2010

I want to make an application which turns on my computer. A Wake-on-Lan application should do the trick. I allready created something which sends data over UDP, i can see that it sends the data (with wireshark) but it does not send the correct data.

[Code]...

View 2 Replies

Create A Magic 8 Ball That Would Display Answers Via Array?

Apr 17, 2011

The goal in this assignment was to create a Magic 8 Ball that would display answers via array.Here's what I got down so far, now I apologize once again, I forgot most of the stuff so I don't even know if it is REMOTELY close to what it's suppose to be

Public Class Form1
Dim ArrayRes(7) As String
Private Sub btnASK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnASK.Click

[code]....

View 4 Replies

Designing Magic Square - Scanning Array With Function

Mar 18, 2011

I'm designing a 3 x 3 Magic Square, where the 3 x 3 tables are made of up three adjacent list boxes. Upon starting the program, the 3 x 3 square consists only of the character "?" to represent a variable that has yet to be defined. The user will input through text boxes and button presses the characters 1 to 9, replacing the highlighted undefined "?' with the desired number. I'm required to include a Function procedure that can, at any time scan the 3x3 table and return an integer value of -1 if an undefined character "?" is present, a value of 0 if the rows, columns and diagonals do not sum to the same value, or the sum common to all rows columns and diagonals.

To start with I defined a 2D array and undefined.
Dim mSquare(2,2) As String
Dim undefined As String = "?"

Then I used a Sub to set the 3x3 table as undefined which I did not show to save space. Next I used a Sub to update the highlighted characters, allowing only one list box to be selected at a time and which I hope also assigns the the values to the array as they are updated. I removed parts of the code so this post isn't too big.

If lstCol2.SelectedIndex = -1 And lstCol3.SelectedIndex = -1 Then
lstCol1.Items(lstCol1.SelectedIndex) = input
txtInput.Text = ""
End If
For i As Integer = 0 To 2
[Code] .....

What I'm stuck on is the Function design. I'm trying to design something to scan the array, and give back an integer depending on the results, which are to return an integer value of -1 if an undefined character "?" is present, a value of 0 if the rows, columns and diagonals do not sum to the same value, or the sum common to all rows columns and diagonals.

I'm currently trying
Function checkSquare(ByRef mSquare As String) As String
For i As Integer = 0 To 2
[Code] .....

At the moment I keep getting the error "Public Readonly Default Property Chars(index As Integer) As Char". I keep getting an error like this even using a single variable and defining each j individually, and I'm wondering if its possible to pass arrays to functions or do I need to do something else. Is what I'm trying to do even possible? I did a longer method in which I just check all the entries individually but I'm hoping there is a more efficient way. Its my plan B for now.

View 6 Replies

If File Is An Image Using .Net Framework Not By Checking Magic Numbers

Apr 20, 2011

With all the smarts of actually loading images being done by the .net framework, seems like I shouldn't have to repeat it all in my code by checking for magic numbers, or using a hack like this:[code]Am I missing something obvious, like System.Drawing.IsImage(stream)?

View 1 Replies

When Build Project To Create Exe / Want To Include 3d Control Magic.exe Into It

Mar 11, 2010

I've used 3d control magic for VB.NET to create shaped forms.When I bulid my project to create an exe, I want to include 3d control magic.exe into it, to be installed automatically in the clients computer.

View 1 Replies

.net - Photoshop Like Magic Wand For Selecting Pixels Of A Similar Color?

Sep 15, 2011

I need to write some vb.net code that looks at a picture and "removes" the blackish pixels.Here's the scenario. A wound care doctor takes a picture of a persons hand on a flat bed scanner. The nice pink palm print is there but it is surrounded by blackish pictures. I want to make the picture pop by programatically "removing" or recoloring the pixels that are in the blackish range. i.e. the Photoshop magic wand select and delete.I have not code to start off. Hoping for some reference code and not just pcode.

View 1 Replies

Using 'magic Numbers' In Code Is Not Good Practice And Makes Maintenance Difficult

Feb 26, 2012

"First of all please TURN OPTION STRICT ON.I make no apology for the capitals - I consider it that important.When you do you will see that you are still using HorizontalAlignment instead of ContentAlignment.VB is converting from one to the other for you.Although that works fine here there are many cases when it will not be what you intended and can cause some very hard to find bugs.Under Tools | Options | Projects and Solutions | VB Defaults Set: Option Strict ON, Option Explicit ON, Option Infer OFF".I did do this but it showed no errors, so I placed 'Option Strict On' at the start of the code, it then showed HorizontalAlignment with the squiggly line. I did edit my code to show this but I think you must have read it before I did. All other suggestions I will note and from now try to implement.Using "magic numbers" in the code is not good practice and makes maintenance difficult.Declare all such numbers at the top and use the names in the code.Is this what you mean? Const SpinTime As Integer = 500

Now when ever I refer in code to SpinTime it will always be 500..Change the NumberOfBoxes to 10 and run the app.In mine, to change boxes to 10 I needed to alter the code in 5 places, in yours 1 place! Talk about proof of the pudding etc.Now to my question, in the program when the start button is clicked and the five random numbers are displayed I have to stop and restart the program to generate five more. So I thought I would create another button 'Reset' this I did and all worked but it seemed a waste so I then just kept the start button in place and changed the text to Reset eg [code] This is fine the one thing I can't figure is how to replace the five numbers that were removed so that it is picking 5 from 500 every time. Now I'm at the end of all this writing I have it! just comment out the line 'Numbers.Remove(Number).

View 1 Replies

VB 2010 - "3x3 Magic Square" - Use A Function That Returns An Integer Value?

Mar 16, 2011

I have a project to make a "3x3 magic square" and I'm not quite sure how to begin. A magic square is a 3x3 table of 9 values where the sum of the values along any row, column, or either diagonal all add up to the same value.I have to use listboxes to create a form displaying a table of 3 rows and 3 columns whose elements can be individually updated. The solution should have the following features:

- a procedure that initializes a Listbox to hold the value "?", representing the value "undefined", in each of its locations. The number of locations should be provided as a n additional parameter.

- a procedure that will update the contents of a listbox by replacing the currently highlighted entry with a value provided as a second argument. The program should at most have at most one entry among the listboxes highlighted.

I am trying to use a Function that returns an integer value: -1 if not all the elements on the table contain values, 0 if the rows/columns/diagonals don't sum up to the same value, or the sum common to all the rows columns, and diagonals is returned if everything is alright.The user will enter a 3x3 set of numbers. The program will monitor the status of the table as values are entered and displays the status in a textbox that describes if a magic square currently exists. If not all the entries have been made to the table, then the textbox should display a message indicating so.

View 1 Replies

Code/regular Expression/magic That Can Detect If This Text Contains A Piece Of SQL Query Instead Of Normal Harmless Text?

Sep 21, 2010

I came to a company that already has a fully grown project... but coders that worked here before me didn't follow conventions and didn't use parametrized SQL queries... as a result there is over 1000 places in a very huge project that can possibly be vulnerable to SQL injection...

I need to find a solution that will automatically detect if there is an SQL injection in the code. So, for example there is a form which allows user to enter comments regarding a product, which will be sent to database on submit... how can we make sure that a user didn't enter a harmfull query instead of a normal text?

Is there any advanced code/regular expression/magic that can detect if this text contains a piece of SQL query instead of normal harmless text? I will accept any links, pieces of code in any language or even commercial software that will do that for me.

View 5 Replies

Magic The Gathering: Deck Runner Images - Add A Deck, And Then Test It Out

Mar 29, 2012

I have been working on a program in where i can add a deck, and then test it out, for various reasons. (Too much mana, not enough mana, ect.) and i have been wanting to add pictures so i could see what cards are popping up, but have no idea on how to do that. i can use my.resources to add pictures for my own cards, but i have no idea on how to go about giving the cards pictures.

Here is my code:

Public Class Form4
Public card1drawn As Integer = 0
Public card2drawn As Integer = 0

[CODE]...

View 1 Replies

C# - Declaring Hex Constant In .net?

Apr 20, 2012

How can I convert the following code into VB.Net?

private const UInt32 temp = 0xE6359A60;

I tried the following but it doesn't work.

Public Const temp As System.UInt32 = 0xE6359A60

View 2 Replies

Declaring Pi As A Constant?

Apr 12, 2011

visual basic 2008 express

' the following lines declare the variables and constants
Dim intDiameter As Integer
Const dblPI As Double = 3.14159
Const dblAREA As Double = 140125
Dim intLabel As Integer

Private Sub PizaSliceCalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]...

I made a working program to calculate piza slices, i was told i needed to declare pi and the areas as constants. when i rewrote the program it no longer works. the result keeps coming back as 0.

View 8 Replies

Getting A Constant From A Form

Mar 13, 2010

I am looping through all of the forms in my app, and I am needing to get a value from the form somehow.Example, say if I have the form named "This Form" and somewhere in that form, dont know if you can use the tag property for this or not, but I need to put a word like "Tall" for an external reference to the form.[code]"How do I get another value like the forms tag or something else".

View 5 Replies

Gravitational Constant ?

Jan 10, 2010

Explain or send me in the right direction.

View 2 Replies

Use String As A VB Constant?

May 17, 2012

I have strMyColor = "Red".I would like to make lblMyLabel.BackColor to be red.Without using a variable the code would be this:

lblMyLabel.BackColor=Color.Red

I tried using the variable like this: lblMyLabel.backcolor="Color." & strMyColor

But the error is that a string can't be converted to System.Draw.Color. I understand that, as the string "Color.Red" is not the same as the VB constant Color.Red.Is there a way I can construct a valid vbConstant from a string?

View 10 Replies

Can't Declare Constant In Namespace?

Dec 25, 2009

I mean why? I mean to organize things I often turn modules into classes where all the methods are share.But then I thought, why not organize them into namespace?But then we can't declare constant in namespace.

View 10 Replies

Constant Cannot Be Target Of An Assignment

Jun 12, 2011

i am making a program on visual basic 2010 and part of my objective is to calculate the tax, i am trying to calculate the TAX so this is part of my code and this is the only part which gives me errors:[code]

1. Constant cannot be target of an assignment

2. value of type 'string' cannot be converted to 'System.windows.forms.Lebel'.

View 2 Replies

Constant Expression Is Required

Apr 14, 2011

I'm trying to make following subroutine work. The problem is this part of the statement.[code]I've tried everything and can't seem to come up with a constant to use here.[code]

View 3 Replies

Constant Expression Is Required?

Apr 27, 2010

I have created a program that creates a blank database in a users account (each user has a seperate folder when registered) by pressing a command button, i have got it to create the database but when i try to populate it with a table to go to the correct folder i get an error

Constant expression is required
the code im using for this is:
Const strConnection As String = ("Provider=Microsoft.Jet.OLEDB.4.0;" & _

[code].....

View 1 Replies

Constant Values For Windows?

Jun 25, 2009

where i can find out constant value used to control the windows. like i'm using wndproc to disable validation and i use constant value for closing of form and that value is &HF060&

i was also looking for constant value for leaving the form. is there any place where i can find out these values?

View 3 Replies

Constant Window Flashing?

Jun 16, 2011

Alright, So i have two forms open. One in a listview and i have another window with a browser control in it. The browser is adding data to the listview but i made it so it hides while doing this using Me.Hide(). I can make it appear if i click the menu item "Show browser" i made.when im on Form1 (the listview) and its doing its thing with the browser window hidden. It keeps making form1 flash. Well not flash but like the browser window is poping to the front (while hidden) causing me not to be able to click on anything on Form1.This happen everytime the web browser navigates somewhere.Making Form1 always on top fixes it, but it also gets on top of other programs like my web browser . I want it to be on top only to the web browser.

View 1 Replies

Declaring Constant On VB 2010?

Feb 11, 2012

Having problem declaring constant on Visual Basic. rents is $200 per hour and is charge by minutes this is what I have so far.

const TOTAL_CHARGE_GROUP as Interger = 200 ©

View 8 Replies

Difference Between Enum And Constant?

May 13, 2009

What's the difference between enum and constant?Are they useful in real-life programming? or do they exist solely to make coding more tidy? Do they serve any real purpose?

View 1 Replies







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