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

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

Related

Open popup conditional from controler MVC And Retrieve the answer

I want from my controller open a poup-up that contains data and ask a question to the user. According to his answer, I continue or stop treatment.
Function Traitement(model As TraitementViewModel, confirm_value As String) As ActionResult
Try
If (ModelState.IsValid) Then
Dim exception As Exception = Nothing
Dim mois As Integer = Mid(model.dateTraitement, 4, 2)
Dim annee As Integer = Right(model.dateTraitement, 4)
Session("mois") = mois
Session("annee") = annee
Dim extract As Extraction = New Extraction()
Dim result As Integer = extract.Recherche(mois, annee).Rows.Count()
If (result <> 0) Then
OPEN POPUP
Artciles Montant
1 100
2 200
Do you want continue
YES NO
IF(confirm_value = "yes") Then
continue...
Else
Exit Function
Else
continue...
End If
End If
End Function

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

How to filter Flat File Source using script component

I have the following scenario:
I have thousands of text files with the below format.The column names are written in separate lines where as the row values are delimited by Pipe(|).
START-OF-FILE
PROGRAMNAME=getdata
DATEFORMAT=yyyymmdd
#Some Text
#Some Text
#Some Text
#Some Text
#Some Text
START-OF-FIELDS
Field1
Field2
Field3
------
FieldN
END-OF-FIELDS
TIMESTARTED=Tue May 12 16:04:42 JST 2015
START-OF-DATA
Field1Value|Field2value|Field3Value|...|Field N Value
Field1Value|Field2value|Field3Value|...|Field N Value
------|...........|----|-------
END-OF-DATA
DATARECORDS=30747
TIMEFINISHED=Tue May 12 16:11:53 JST 2015
END-OF-FILE
Now I have a corresponding SQL Server table, where I can easily load the data as destination.
Since I am new to SSIS, having trouble as to how to write the Script Component so that I can filter the Source Text files and easily load into sql server table.
Thanks in advance!
There are a few ways to do it. If the format of the files are constant, there are some useful properties of the flat file connection manager editor. For example, you can add a new flat file connection into the connection managers. There are some properties such as "Rows to skip" for the above file, you could set this to 18. Then it would start at the columns line with the "|".
Another property of the flat file connection manager that may be useful is that if you open the flat file connection manager, and then click on columns in the side menu, you can set the column delimter to the pipe "|"
But if the format of the file will change, e.g. variable number of header rows, you can use a script task to remove any non-piped rows. e.g. the header and footer.
For example, you can add a method such as file.readalllines and then edit or remove the lines as needed then save the file.
Info about that method is here:
https://msdn.microsoft.com/en-us/library/s2tte0y1%28v=vs.110%29.aspx
e.g. to remove last line in script task
string[] lines = File.ReadAllLines( "input.txt" );
StringBuilder sb = new StringBuilder();
int count = lines.Length - 1; // all except last line
for (int i = 0; i < count; i++)
{
sb.AppendLine(lines[i]);
}
File.WriteAllText("output.txt", sb.ToString());
USE Below VB Script in your SSIS SCript Component Task as source
enter code here
Imports System
Imports System.Data
Imports System.Math
Imports System.IO
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute()> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
'Private strSourceDirectory As String
'Private strSourceFileName As String
Private strSourceSystem As String
Private strSourceSubSystem As String
Private dtBusinessDate As Date
Public Overrides Sub PreExecute()
MyBase.PreExecute()
'
' Add your code here for preprocessing or remove if not needed
''
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
'
' Add your code here for postprocessing or remove if not needed
' You can set read/write variables here, for example:
Dim strSourceDirectory As String = Me.Variables.GLOBALSourceDirectory.ToString()
Dim strSourceFileName As String = Me.Variables.GLOBALSourceFileName.ToString()
'Dim strSourceSystem As String = Me.Variables.GLOBALSourceSystem.ToString()
'Dim strSourceSubSystem As String = Me.Variables.GLOBALSourceSubSystem.ToString()
'Dim dtBusinessDate As Date = Me.Variables.GLOBALBusinessDate.Date
End Sub
Public Overrides Sub CreateNewOutputRows()
'
' Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
' For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
'
Dim sr As System.IO.StreamReader
Dim strSourceDirectory As String = Me.Variables.GLOBALSourceDirectory.ToString()
Dim strSourceFileName As String = Me.Variables.GLOBALSourceFileName.ToString()
'Dim strSourceSystem As String = Me.Variables.GLOBALSourceSystem.ToString()
'Dim strSourceSubSystem As String = Me.Variables.GLOBALSourceSubSystem.ToString()
'Dim dtBusinessDate As Date = Me.Variables.GLOBALBusinessDate.Date
'sr = New System.IO.StreamReader("C:\QRM_SourceFiles\BBG_BONDS_OUTPUT_YYYYMMDD.txt")
sr = New System.IO.StreamReader(strSourceDirectory & strSourceFileName)
Dim lineIndex As Integer = 0
While (Not sr.EndOfStream)
Dim line As String = sr.ReadLine()
If (lineIndex <> 0) Then 'remove header row
Dim columnArray As String() = line.Split(Convert.ToChar("|"))
If (columnArray.Length > 1) Then
Output0Buffer.AddRow()
Output0Buffer.Col0 = columnArray(0).ToString()
Output0Buffer.Col3 = columnArray(3).ToString()
Output0Buffer.Col4 = columnArray(4).ToString()
Output0Buffer.Col5 = columnArray(5).ToString()
Output0Buffer.Col6 = columnArray(6).ToString()
Output0Buffer.Col7 = columnArray(7).ToString()
Output0Buffer.Col8 = columnArray(8).ToString()
Output0Buffer.Col9 = columnArray(9).ToString()
Output0Buffer.Col10 = columnArray(10).ToString()
Output0Buffer.Col11 = columnArray(11).ToString()
Output0Buffer.Col12 = columnArray(12).ToString()
Output0Buffer.Col13 = columnArray(13).ToString()
Output0Buffer.Col14 = columnArray(14).ToString()
Output0Buffer.Col15 = columnArray(15).ToString()
Output0Buffer.Col16 = columnArray(16).ToString()
Output0Buffer.Col17 = columnArray(17).ToString()
Output0Buffer.Col18 = columnArray(18).ToString()
Output0Buffer.Col19 = columnArray(19).ToString()
Output0Buffer.Col20 = columnArray(20).ToString()
Output0Buffer.Col21 = columnArray(21).ToString()
Output0Buffer.Col22 = columnArray(22).ToString()
Output0Buffer.Col23 = columnArray(23).ToString()
Output0Buffer.Col24 = columnArray(24).ToString()
End If
End If
lineIndex = lineIndex + 1
End While
sr.Close()
End Sub
End Class
Code End

Can't get listbox to display

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

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