|
I want to add header to my csv file how please help me
Dim parsedData = New List(Of String())()
Using sr = New StreamReader("H:/test.csv")
Dim line As String
line = sr.ReadLine()
Do While line IsNot Nothing
Dim row() As String = line.Split(","c)
parsedData.Add(row)
line = sr.ReadLine()
Loop
End Using
DataGridView1.ColumnCount = 6
For i As Integer = 0 To 5
Dim sb = New StringBuilder(parsedData(0)(i))
sb.Replace("_"c, " "c)
sb.Replace("""", " ")
DataGridView1.Columns(i).Name = sb.ToString()
Next i
For Each row As String() In parsedData
DataGridView1.Rows.Add(row)
Next row
DataGridView1.Rows.Remove(DataGridView1.Rows(0))
|
|
|
|
|
Great problem description.
You're "reading" the CSV file but want to "add" a header to it.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Why are you using the parsedData object? That just adds complexity to your code. The actual method only needs the following logic:
1. Read the first line of the csv file (assuming it contains the header labels), and use the fields from that to set your DataGridView headers.
2. Read the remaining lines one by one, and use them to fill the data rows of the dgv.
|
|
|
|
|
I Have no idea what happened here. I finally just deleted the whole project and started
over. I recreated the old code a little at a time and now everything works. I am sorry for
this post. If anyone has ever encountered this problem I would be interested in what happened
so I don't do it again.
Again, sorry.
I do not know why I have never encountered this before but here goes.
I have created a new windows forms project called MyProject.
I create a new UserControl within the project called Test.vb the normal way:
1. Right click MyProject
2. Click Add + UserControl
I do not modify the control in any way.
Compile and build is ok.
I drag the new 'Test' control from the toolbox to the main form and save.
The designer saves the Test control with these entries:
Friend WithEvents Test1 as MyProject.Test
Private Sub InitializeComponent()
Me.Test1 = new MyProject.Test
... plus other normal initialization
End Sub
For some reason the compiler does not recognize the 'MyProject.Test' control as
part of the project. It indicates that 'Test' is 'not defined'. If I change the declaration in
the MyProject.Designer.vb 'Test' without 'MyProject.' reference, the compiler builds with
no errors.
However the next time I edit the form, the designer saves the control
the same way; ie. MyProject.Test.
Why does the compiler not recognize Test as part of MyProject.Test?
thank you
-- modified 27-Jan-18 5:07am.
|
|
|
|
|
I am trying to make a simple score card by entering the score for each player for each round in a lbl_round.text and then having each round show in a Lbl_total.text
Problem is, if player 1 in round 1 scores 7 all is fine round1.text shows 7 and total.text shows 7 but when I come again to player 1, round score may be 6 which should show in total score as 13 but instead I get 76. Below is the code:
Static counter = 0
Dim labels = {Lbl_roundscore1, Lbl_roundscore2, Lbl_roundscore3, Lbl_roundscore4}
Dim totals = {Lbl_total1, Lbl_total2, Lbl_total3, Lbl_total4}
labels(counter).Text = Txt_input.Text
totals(counter).Text = totals(counter).Text + labels(counter).Text
Txt_input.Text = String.Empty
counter = If(counter = labels.Count - 1, 0, counter + 1)
|
|
|
|
|
If you "add" strings then you really expand them - that means :
the Result of adding "7" and "6" is "76". That is what your code does.
What you want to have is adding the numeric values - so you should cast each string perhaps to an Integer and add them now. Finally you convert the Integer-Value back into your Result ...
|
|
|
|
|
Ralf Meier wrote: you should cast each string perhaps to an Integer
You can't "cast" a string to an integer; you need to parse it.
Int32.TryParse[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
oO ... I wrote cast and I meant convert - but I think it's clear what I tried to say ...
|
|
|
|
|
Thanks Ralf for taking the time to answer will look in to what you suggest.
|
|
|
|
|
This is the kind of problem you get when using controls to store your game state.
DON'T DO THAT! Controls are there to SHOW and EDIT your data, not to hold it for you.
Maintain your values (state) in a class, or other appropriate storage, such as a structure, designed for the purpose. The controls can then get their values from the game state storage. Doing this also frees you from parsing or casting data back and forth.
|
|
|
|
|
Well excuse me Dave for being the fool, only just started with VB so will go away and try to decipher what it is you are trying to tell me.
|
|
|
|
|
Well here's what I came up with after reading some tutorials it works so I'm happy but is it correct?
Static counter = 0
Dim labels = {Lbl_roundscore1, Lbl_roundscore2, Lbl_roundscore3, Lbl_roundscore4}
Dim totals = {Lbl_total1, Lbl_total2, Lbl_total3, Lbl_total4}
labels(counter).Text = Txt_input.Text
Dim num1 As Single = Val(labels(counter).Text), num2 As Single = Val(totals(counter).Text)
Dim Sum As Single = num1 + num2
totals(counter).Text = Sum.ToString
Txt_input.Text = String.Empty
counter = If(counter = labels.Count - 1, 0, counter + 1)
modified 26-Jan-18 12:56pm.
|
|
|
|
|
"Dim Sum is Single". Poor Dim Sum
How would you define "correct"? If it works, it works. It's not nicely parsing and displaying error-messages if someone enters a text, or Roman numerals.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy,
Yes it works and not displaying error messages if you enter text or roman numerals, so for me that's OK.
By correct I guess I mean is it good coding or is any code good if it works?
|
|
|
|
|
"Good" is in the eyes of the beholder; I prefer to see error-handling when getting user-input. If you don't mind, who am I to say it is wrong? Are you sure that "static" is what you want, or do you just need some int? And again, you're using the UI to keep a current "state"; meaning, you're abusing the controls for something that should be a separate variable.
..and no documentation. No single comment. I'd be more impressed if the amount of totals were variable, but impossible to say if that's logical from a user-viewpoint. Depends on what the code is required to do.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Are you sure that "static" is what you want, or do you just need some int?
Not sure what I want only started using it 2 days ago.
The program is only for me when playing a game with family that scores each round and has a running total. It's so small it doesn't need comments so is it good? It does what I want without errors it's for personal use so I guess it's good.
Thanks to all who have contributed.
|
|
|
|
|
MallardsReach wrote: It does what I want without errors it's for personal use so I guess it's good. Then you succesfully met the demand of the customer
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello!
Right now I am first year student in University with a bit of time on my hands, so I wanted to combine 2 of my passions - poker & programming.
I want to build an app, that would count my fold count in a row (in PokerStars environment).
How I have imagined it, would be a small box next to my username that overlays opened poker table, showing how many times have I folded in a row real time. Similar to HU display.
Easiest way to count folds, would be garbing info from hand histories. Where I am stuck is, how do I display the info.
It could work as I input my players name, and then the program automatically finds the right position (the seat where the player sits) and then 20px to the right, and 20 pix to the left displays small overlaying box with a value of Fold count.
I need to figure out, how can I input string value, such as the player name, and the program checks the opened player table window, and gives me x and y pixel coordinates of where this players name is displayed on the game table window.
My question is, how do these 3rd party app companies can take the info from the opened poker table application window? What method do they use? If someone could steer me in the right direction, that would be awesome! For all the answers, thanks in advance!
|
|
|
|
|
I have been working with vb.net but I'm new to vbscript. Please can someone help me out.
I'm try to code vbscript to can help me to silently install mysql, install mysql service and setup root password. below are my code:
echo off
cls
set objShell=wscript.createObject("wscript.shell")
Wscript.Echo "Starting Install..."
set mysql_msi="C:\Mysql\mysql-essential-6.0.10-alpha-win32.msi"
set mysql_svname=MySQL
set mysql_odbc="C:\Mysql\mysql-connector-odbc-3.51.27-win32.msi"
set mysql_gui="C:\Mysql\mysql-gui-tools-5.0-r17-win32.msi"
set mysql_datadir="C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 6.0\data"
set mysql_data2="C:\Program Files\MySQL\MySQL Server 6.0\data"
set mysql_cmd="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql' WITH GRANT OPTION;"
set mysql_inst="msiexec /i %mysql_msi% /qn"
objShell.Run(mysql_inst)
Wscript.Echo "MySQL Version 6.0.7 installed..."
rem md %mysql_data2%
objShell.Run("C:\Program Files\MySQL\MySQL Server 6.0\bin\mysqlinstanceconfig.exe" -i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPMENT DatabaseType=MYISAM Port=3306 RootCurrentPassword=mysql)
Wscript.echo "MySQL Instance Configured...Service started..."
rem Uncomment next line to allow root access from any pc...
"C:\Program Files\MySQL\MySQL Server 6.0\bin\mysql.exe" -uroot -pmysql -e %mysql_cmd%
msiexec /qn /i %mysql_odbc% /L* C:\MSI-MySQL-ODBC-Log.txt
echo ODBC Connector installed...
msiexec /qn /i %mysql_gui% /L* C:\MSI-MySQL-GUI-Log.txt
Wscript.Echo "MySQL GUI Tools installed..."
echo on
explorer "C:\Program Files\MySQL\MySQL Server 6.0\bin"
|
|
|
|
|
I doubt the user wants anything to be installed silently. Best to simply specify that the user has to have it installed before your app can install. Give the user control.
|
|
|
|
|
how can i create a vb project to glow the light of logic gate output?
|
|
|
|
|
Probably by coding an application that sends messages to the gate. But since you have given no details of the devices or configuration it is impossible to suggest anything more.
|
|
|
|
|
Hi,
I have a couple of windows applications that use MS Access to print reports. They were built on MS Access 2007, and worked fine until I was forced to upgrade to Office365 and thus MS Access 2016. Unfortunately (apparently) Office365's version of Office 2016 does not allow you to have other Office versions installed, so I had to remove my Access 2007 version.
The simplified version of my code that worked fine until now:
Dim oAccess As Access.Application
Dim x As Long
AccessExecutablePath = New FileInfo("C:\Program Files\Microsoft Office\root\Office16\MSACCESS.EXE").FullName
x = Shell(AccessExecutablePath & " " & Chr(34) & DatabasePath & Chr(34) & " /runtime", AppWinStyle.MinimizedNoFocus)
oAccess = New Access.Application
oAccess = GetObject(DatabasePath)
oAccess.PrintReport("Some_Report_Saved_In_MSACCESS")
Apparently when you install Office 2016, it no longer has the necessary interop driver for Access, and the code no longer works.
However, all microsoft's (I suppose outdated) documentation still says to use the code above.
Here is my question:
Has anyone else faced this issue, and more importantly can anyone suggest a solution, or another method to interact with the Access client?
Regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Have you tried the code from this MSKB article[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Thanks, I have read this article, but it only covers data access, whereas I specifically need the reports / printing functionality.
The basic idea is that my access database is linked to an MS SQL database, and takes its data from there. Data access simply goes through MS SQL client.
Regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|