Can't get listbox to display - listbox

I am stuck here. I can't get the solution to print out into the listbox. I just can't find out what I am missing. I need help. Anything you see would be a big help. This is all the code from my program:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For years As Integer = 3 To 20
Lifebox.Items.Add(years.ToString)
Next years
Lifebox.SelectedIndex = 0
End Sub
Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
Me.Close()
End Sub
Private Sub DisplayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayButton.Click
Dim cost As Double
Dim life As Double
Dim period As Double
Dim numberperiod As Double
Dim salvage As Double
Dim depreciation As Double
Dim isConvertedCost As Boolean
Dim isConvertedLife As Boolean
Dim isConvertedSalvage As Boolean
isConvertedCost = Double.TryParse(Assetbox.Text, cost)
isConvertedLife = Double.TryParse(Lifebox.Text, life)
isConvertedSalvage = Double.TryParse(SalavageBox.Text, salvage)
For numberperiod = 1 To period Step 1
depreciation = Financial.DDB(cost, salvage, life, numberperiod)
DepBox.Text += numberperiod.ToString & " -> " & Convert.ToString(depreciation) _
& ControlChars.NewLine
Next numberperiod
If isConvertedCost AndAlso isConvertedLife AndAlso isConvertedSalvage Then
DepBox.Text = " Year Depreciation "
Else
MessageBox.Show("The cost, life, and salvage values must be numeric.",
"Sonheim Manufacturing Company", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Assetbox.Focus()
End If
End Sub
End Class

Related

VBA to read in tab delimited file

I have some code which reads in a tab delimited file where cell reference B2 matches the reference in the first column in the tab delimited file. This works fine where the text file is small. The below works on a sample file with aa bb and cc as the headers with dummy data.
Option Explicit
Sub TestImport()
Call ImportTextFile(Sheet1.Range("B1"), vbTab, Sheet2.Range("A4"))
End Sub
Public Sub ImportTextFile(strFileName As String, strSeparator As String, rngTgt As Range)
Dim lngTgtRow As Long
Dim lngTgtCol As Long
Dim varTemp As Variant
Dim strWholeLine As String
Dim intPos As Integer
Dim intNextPos As Integer
Dim intTgtColIndex As Integer
Dim wks As Worksheet
Set wks = rngTgt.Parent
intTgtColIndex = rngTgt.Column
lngTgtRow = rngTgt.Row
Open strFileName For Input Access Read As #1
While Not EOF(1)
Line Input #1, strWholeLine
varTemp = Split(strWholeLine, strSeparator)
If CStr(varTemp(0)) = CStr(Range("B2")) Then
wks.Cells(lngTgtRow, intTgtColIndex).Resize(, UBound(varTemp) + 1).Value = varTemp
lngTgtRow = lngTgtRow + 1
End If
Wend
Close #1
Set wks = Nothing
End Sub
I am trying to get the below bit of code to work using ADO as this will run much faster on a text file with a couple of million records however I am getting an error on the '.Open str' part of the code (no value given for one or more required parameters).
It looks like it is to do with how I am defining the string- could you review and see if there is something I am missing...?
Sub QueryTextFile()
t = Timer
Dim cnn As Object
Dim str As String
Set cnn = CreateObject("ADODB.Connection")
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.ConnectionString = "Data Source=C:\Users\Davids Laptop\Documents\Other Ad Hoc\Test Files\;Extended Properties=""text;HDR=Yes;FMT=Delimited;"""
cnn.Open
Dim rs As Object
Set rs = CreateObject("ADODB.Recordset")
str = "SELECT * FROM [test1.txt] WHERE [aa]=" & Chr(34) & Range("B2") & Chr(34)
With rs
.ActiveConnection = cnn
.Open str
Sheet1.Range("A4").CopyFromRecordset rs
.Close
End With
cnn.Close
MsgBox Timer - t
End Sub

Ruby on Rails OpenSSL HMAC Equivalent to VB.NET/C# HMAC

I'm running into a problem where I cannot get the Hash value from VB.Net to match the hash value in Ruby on Rails. I'm wondering if this is almost the equivalent way to do it. The problem relies in my VB code.
Here's an example of the code:
Ruby
key = 'key'
data = 'The quick brown fox jumps over the lazy dog'
digest = OpenSSL::Digest::MD5.new
hmac = OpenSSL::HMAC.hexdigest(digest, key, data)
VB.Net
Dim key As String = "key"
Dim value As String = ""
Function getMD5Hash(ByVal input As String) As String
Dim md5Hasher As New HMACMD5()
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input))
Dim sBuilder As New StringBuilder()
Dim i As Integer
For i = 0 To data.Length - 1
sBuilder.Append(data(i).ToString("x2"))
Next i
Return sBuilder.ToString()
End Function
Private Sub Test()
Dim data As String = "The quick brown fox jumps over the lazy dog"
value = getMD5Hash(key + data)
testing.Text = value
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles testBtn.Click
Test()
End Sub

Printing to a Brother printer from VB2013.net using the brother SDK

I have some code that I think should print to my brother printer but it appears to do absolutely nothing. It is driving me mad!!
Anyone any ideas at all please
Dim PrinterName As String = ComboBox1.Text
If PrinterName.Contains("Brother") Then
Dim objDoc As bpac.Document
objDoc = CreateObject("bpac.Document")
Dim STRlbl As String = "C:\BarcodeScans\Application\Label.lbx"
If (objDoc.Open("C:\BarcodeScans\Application\Label.lbx")) Then
objDoc.GetObject("objCompany").Text = Txtbox1.Text
objDoc.GetObject("objName").Text = Txtbox2.Text
objDoc.SetPrinter(PrinterName, True)
objDoc.StartPrint(STRlbl, PrintOptionConstants.bpoDefault)
objDoc.PrintOut(1, PrintOptionConstants.bpoDefault)
objDoc.EndPrint()
objDoc.Close()
End If
It doesn't fail or error,Steps through every line as it should, it just does not print.
The label/template prints fine from my PC connected direct to the Brother printer via usb. Printer is a PT-9700PC
I'm stumped.
Imports bpac
Imports System.Drawing.Printing
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim pkInstalledPrinters As String
' Find all printers installed
For Each pkInstalledPrinters In _
PrinterSettings.InstalledPrinters
ComboBox1.Items.Add(pkInstalledPrinters)
Next pkInstalledPrinters
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim PrinterName As String = ComboBox1.Text
Debug.Print(PrinterName.ToString)
If PrinterName.Contains("Brother") Then
Dim objDoc As bpac.Document
objDoc = CreateObject("bpac.Document")
Dim STRlbl As String = "C:\Users\...\UPC-A.lbx"
If (objDoc.Open(STRlbl)) Then
objDoc.GetObject("tUPC-A").Text = TxtBox1.Text
objDoc.GetObject("tRetail").Text = TxtBox2.Text
objDoc.GetObject("tBarCode").Text = TxtBox3.Text
objDoc.SetPrinter(PrinterName, True)
objDoc.StartPrint(STRlbl, PrintOptionConstants.bpoDefault)
objDoc.PrintOut(1, PrintOptionConstants.bpoDefault)
objDoc.EndPrint()
objDoc.Close()
End If
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text <> "" Then
Button1.Enabled = True
End If
End Sub
End Class

How to see Items in a ListBox Longer than the width of the control

I have a List Box which have certain dimentions
Some of the Items are loger than the width of the ListBox control.
When I pass the mouse over these Items I want to see all the name.
I'm using vb.net
Try this:
Private Sub ListBox1_MouseMove (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
Dim ListMousePosition As Point = Me.ListBox1.PointToClient(Me.MousePosition)
Dim itemIndex As Integer = Me.ListBox1.IndexFromPoint(ListMousePosition)
If itemIndex > -1 Then
Dim s As String = Me.ListBox1.Items(itemIndex).ToString()
Dim g As Graphics = Me.ListBox1.CreateGraphics()
If g.MeasureString(s, Me.ListBox1.Font).Width > Me.ListBox1.ClientRectangle.Width Then
Me.ToolTip.SetToolTip(Me.ListBox1, s)
else
Me.ToolTip.SetToolTip(Me.ListBox, "")
End If
g.Dispose()
End If
End Sub

How to read bytes in chunks to avoid out of memory exception? Or something else

after searching and trying to find a solution for 2 days i finnaly decided to post here to ask for help...
I have a code to read and write bytes of a file (like an hex editor) working very good taken from here: http://www.novahq.net/forum/showthread.php?t=42592
Here goes the code:
Public Class Form1
Private Shared Function HexStringToByteArray(ByRef strInput As String)
As Byte()
Dim length As Integer
Dim bOutput As Byte()
Dim c(1) As Integer
length = strInput.Length / 2
ReDim bOutput(length - 1)
For i As Integer = 0 To (length - 1)
For j As Integer = 0 To 1
c(j) = Asc(strInput.Chars(i * 2 + j))
If ((c(j) >= Asc("0")) And (c(j) <= Asc("9"))) Then
c(j) = c(j) - Asc("0")
ElseIf ((c(j) >= Asc("A")) And (c(j) <= Asc("F"))) Then
c(j) = c(j) - Asc("A") + &HA
ElseIf ((c(j) >= Asc("a")) And (c(j) <= Asc("f"))) Then
c(j) = c(j) - Asc("a") + &HA
End If
Next j
bOutput(i) = (c(0) * &H10 + c(1))
Next i
Return (bOutput)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myFile As String = "..\..\Test.jpg"
Dim myBytes As Byte() =
My.Computer.FileSystem.ReadAllBytes(myFile)
Dim txtTemp As New System.Text.StringBuilder()
For Each myByte As Byte In myBytes
txtTemp.Append(myByte.ToString("X2"))
Next
RichTextBox1.Text = txtTemp.ToString()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim myFile As String = "..\..\Test2.jpg"
Dim myBytes As Byte() = HexStringToByteArray(RichTextBox1.Text)
My.Computer.FileSystem.WriteAllBytes(myFile, myBytes, False)
End Sub
End Class
This is working very good, BUT only with small/medium size files. If i try to load a 512MB or a bigger file i will get "System.OutOfMemoryException" error.
I know that in order to make this work (read bigger files without error) i have to read files in small pieces (or chunks whatever you wanna name it), or maybe read it byte by byte i suppose...
The only problem is that i couldn't find a way to do it. I did find some codes but for some reason i wasn't able to make that codes work :(
I apreciate if someone could give me a push on this.
...However, i've thinking and maybe i don't need to read the whole file because i just need to add some bytes to the end of the file and then remove those again.
I'll try to explain what i need:
I only need to add this "504B0506000000000000000000000000000000000000" bytes at the end of a zip in onder do blind/hide contents of zip and then i need to read in again and remove those bytes.
a) Append bytes to the end of file
b) Remove those bytes again
This sounds really simple but from all codes and examples i have found i couldn't adapt them to my code.
Thank you

Resources