Change This Checksum Function To Accept An Integer Input Instead Of A String?
Dec 31, 2009
This function doesn't work if I change the input argument 'pdu' from a string to an int.Would someone please help me figure out what to do here so that the checksum does not add the ascii value of the int argument but rather the actual integer value?I took out a few lines of the actual function but it adds the input argument to a packet sent out via TCP protocol.This function shows the integer value just fine in the string that gets encoded as a byte array. the checksum is wrong.!
''Public Function buildpacket(pdu As Integer) is what I want.
Public Function buildpacket(pdu As String)
Dim packet As String
I have been trying to compute the checksum for a line of hex code. This is to create a hex file which will be loaded onto an embedded micro.Some of you guys may not know how this is done so very briefly:
The underlined bytes are taken and summed. (in this case the decimal 960). and the bold is the checksum Only the 8LSB (or single least significant byte) is needed to compute the checksum... which in this case, 960 = 03C0 in hex, so only C0 is needed.Two's complement is then taken:
step 1) logical not of C0 which is step 2) add one (integer) BIN...........DEC...HEX
[code]....
So here is the code I have been using: (quick mention that in the string passed, the hex bytes are all grouped together, there are no space characters)
Public Sub CreateLine(ByVal Data As String) 'Dim BDataArray(DataLength) As Byte Dim IDataArray(Data.Length) As Integer
[code]....
where i get into trouble is where i commented 'i get into trouble'. My code works, but it's rather crude Now, in that line i first convert the hex value (string) "SChecksum" into an integer. I want to NOT this, so I get my step 2 from my explanation. However, the results appears to be a signed logical NOT. which gives me the wrong answer. My hashed togther version simply subtracts 256 before the not, in order to give me the correct answer.
Basically, I would love for someone to chime in and point out the flaws in my function, and push me towards figuring out the 'proper' way of doing this. Also I can't quite wrap my head around what would happen in the case a string were passed to my function that is over 16 bits, but I imagine I would have to subtract a larger value than 256, before doing the NOT in this case?(whilst we're on the subject of functions, I've used a 'sub', in which case should I used a sub, and which case should I use a function?).
I want the Function to accept List(Of String), Array & String and similarly return List(Of String), Array & String respectively. The Function simply adds a string (month) to the input collection. I just want to use it for string, array and list with needing to think of conversions.
Is there a easy way to input a string or integer into another exe's textbox for example, if i wanted to write into the textbox on the windows calculator '3'.
I am writing a calculator app in VB Express 2008. I'm trying to get the app to accept numeric and operator input while ignoring all the alpha input. In other words taking input from the numeric keypad and the top of the keyboard and ignoring all the letters.
Here's the block of code I have so far:
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If (e.KeyCode >= Keys.D0 OrElse e.KeyCode >= Keys.NumPad0) And (e.KeyCode <= Keys.D9 OrElse e.KeyCode <= Keys.NumPad9) Then Select Case e.KeyCode
[code]....
I can't get vb to recognize the above code it seems to skip right over it. BTW, is 'Keys.Crsel' the same as the caret '^' symbol?
I need to convert a string to get a checksum as follows;
Checksum
The checksum is the 8 LSB (least significant bits) of a simple addition of all octets (note that a message type '30' is two octets with the values 33 hex and 30 hex) following the STX character and until the checksum field. Note that all separators will be included in the checksum, but the STX, checksum and the ETX will not be included.
Dim str as string = "01/00064/O/30/12345678/87654321////////48656C6C6F20576F726C64/"
This should result in checksum = "C2" What type of checksum is this? what should I Google for? CRC, MD5, hash ?
Is there a way to change the display type in a DataGridView. For example the cell has a value of 1, I would like to change that value to display "Weekly" on the DataGridView.
I have the following hex string 40 50 4C 41 59 0D I am transmitting to a piece of equipment, I need to calculate a checksum value to add to the string as the last byte to be sent. The checksum byte is generated in such a manner that the result of addition of all bytes of a message will become 11111111(255). the code that you see here does not work can anyone tell/show me why? Whats important is the checksum calculation.
I would like to know how can I use (read and write) a value in each of my forms. To make it clear: I have 2 forms, Form1 and Form2. I've a string, called string1. If I use in Class Form1 (e.g. at Form1 load) Dim String1 As String, Form2 can't read or change it, because it only exists in Form1. So I would like to have a, let say "general value", a (for example) string, which every form can read&write.
I need to get the AVG of a column in my database i am retrieving. (.csv) I tried using the datatable.compute method but it doesnt work because my data in column is numbers in string format.So i need to either run another query and have the data in integer format?or change the column to integer format? I don't know I am asking as I am brand new to VB and programming for that matter.
I'm currently working with a client's VB.Net code, which was developed for them by a small development shop a few years ago and which they purchased and have been maintaining and uprgrading since. This client's primary developer is out on indefinite (likely permanent) medical leave and I'm now filling in until they bring in a full timer (as I'm a contractor here). My current task is to add some functionality to a the VB.Net code they purchased. I'm finding practices and techniques in the code that absolutely baffle me and can't make the code do what I want. I'm starting to wonder if it's me and was hoping to get some thoughts on the code I've encountered.
For example: Setting a variable to accept the result of a function by calling the function with many parameters, clearing the parameters in the function, setting them to some value, calling another function with those new values, then never using the values returned by the functions. I'll add a code snippet in the first comment since this is already getting long.
I have an object with a number of properties (let's say object.one, object.two, object.three). There are about 30 of these properties and they all hold a string ("Pass" or "Fail"). Right now the existing code checks whether the property has value "Pass" or "Fail" and then runs some code that prints stuff out. That is, the same snippet of code is duplicated 30 times, one for each of these properties.
The code looks something like this If (object.one = ... ) ... End if If (object.two = ... ) ... End if If (object.three = ... ) ... End if
I want to use a loop to clean this mess up (each block is huge), but am not sure how to do it. I was thinking perhaps there was a way such that I might be able to construct a string like "object.one" and run some function that will tell the compiler that this is actually an object's property? That way I could create an array containing the object's name like my array = {"object.one", "object.two", "object.three"} and then do something like, in pseudocode For each string in my array If (some_function(string) = ...) ... End If
Essentially, it would take those massive blocks of duplicated code and reduce it to just one block. Is there such a some_function that I am looking for? This is in VB.net.
This is the program that i made for class to be a calculator for shopping
Public Class frmHarrysGroceryCalculator Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click 'exit button ep
[code]....
I want to be able to use the @ i.e 3@10, meaning 3 items at 10 dollars, in the input box.
In VB.net ,how to accept multiple input? I want to enter marks of a student in 5 subjects to find percentage of marks,but i am not able to understand which vb.net statement i should use to take input in a single line
The project I'm working on is a Multichoice RadioButton quiz with answers and percentintegers. At the end there is a MsgBox that gives the number of answers counted 'correct'and the percent 'correct'. Also after you press the confirm button on that MsgBox it emails the results to the built in information given on the SMTP information. What I am trying to do now is show the input typed into the textbox on FormA in the MsgBox at the very end.
Problem Specification: The Caswell Catering and Convention Service want to install a computerized billing system. You are to develop the application to accept as input the following items:
a.The Name of the customer (string). b.The number of adults to be served (byte). c.The number of children to be served (byte). d.The cost per adult meal (single). e.The room fee (no room fee if catered at the person's home). f.Amount of deposit which is deducted from the bill.
The following is a sample application's input section [code]...
How to accept input into a vb.net console application? How Do I allow people to type into a vb.net console application, and then press enter, and then the console application writes that and uses the console.writeline function to write what the person typed in into the network stream(or whatever its called).
How do I validate textboxes so that they accept only numerical input (1 2 3 etc and not abc @$ etc)? Is there some kind of property of the textbox that I have to change?
I am having a problem on setting the SQL CE table column a field type. What field type does a column that only accepts only two inputs.. Example: If a table has a column named Gender..it should only accepts two types of input...like Make or Female.
I need to write a program using a For Next loop to accept a word as input and determine if its letters are in alphabetical order.
This is the code I came up with but am getting the error "Index and length must refer to a location within the string. Parameter name: length" at run time when I click the button.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
I have written a custom Bindable RichText Box, so I can bind to the Document property. However, as soon as I set my document content, the only keyboard input it accepts is the backspace key (???). No other keyboard input is acknowledged (including the arrow keys).
[[code] 1) Is this violating the phrase static classes should not have state?
2) How can I modify the functions such that they can accept any function (instead of my above situation which only works with F(TResult) and F(T, TResult). [code]
I have buttons generated through code (dynamically). I have to associate an event (the same) to them. I use AddHandler button.click, AddressOf mysub.The issue is that mysub gets a string (mysub(string)), but AddressOf doesn't accept a parameter inside the routine. How can I do this? Using also an alternative to AddressOf.
EDIT:
Public Class Form1 ... Private Sub mysub(ByVal sender As Object, ByVal e As System.EventArgs, ByVal str As String)[code]......
I have a LINQ2Entity problem, I want to get the value, string, from a database, so I select FProducts.Serial_number, and to end the query, I do .ToDictionary. The problem is, it tells me that it doesn't have sufficient parameters, to convert ToDictionary. So I need something like select FProducts.Serial_number, Nothing). ToDictionary. Also FProducts.Serial_number, 0).ToDictionary doesn't work.
Sub GetStatistics(ByVal ProductNumbers As List(Of String), ByRef Passed As Integer, ByRef FailedProducts As List(Of String)) Passed = 0 FailedProducts = Nothing
I've been trying to reuse my bosses vb.net buildpacket code which he has successful used for Serial programming eg. SerialPort1.Write(buildpacket(useraddress,252,"0006","0") for the function listed below.My challenge.Create equivalent functionality for Socket BeginSend() which requires a byte array.Whether modifying the vb.net below or getting a c# equivalent to work, it has been repeatedly recommended to scrap the string concatenation approach for which I have to use Encoding.BigEndianUnicode.GetBytes() and then getting rid of extra bytes with zero values.
I'm lacking in imaging something different which would work for socket programming directly and allow me to eliminate all the hassles that c# integer conversions into string value that can be encoded trouble free.I would need to call the equivalent of the following that would return a byte array rather than a string with the following arguments
1. Source address (0-255) 2. Destination address (0-255) 3. Function code ("0001" through "0100") 4 Packet Data Unit (pdu - some integer value
I've got a little function that just changes empty and null strings to "null":
Public Function CatchString(ByVal stringValue As String) As String If stringValue = "" Or stringValue Is Nothing Or stringValue Is DBNull.Value Then Return "null"[code].....
I added the bit about DBNull because sometimes it gets null values from a database. This doesn't work, though, because it won't take DBNull as a parameter.I tried changing the stringValue parameter from a string to an object, but then the If statement gives this error:
Quote: Object reference not set to an instance of an object.How do I make the function accept DBNull as a parameter?
How can I change the highlighted code to accept an apostrophe.. Presently, it gives an error: Unclosed quotation mark after the characetr string ;'Test Project''. Incorrect syntax near 'Test Project''.