DataGridView Prevent Formatting - vb.net

Hello again I am trying to get the value of a Cell in DGV (datagridview)
but i noticed it was returning a truncated an Rounded up Value.
Value in Cell = 32.71529844248667
but Returned Value = 32.7152984424867
the code i am using
Dim data As String = DGV.Item("latitude", DGV.CurrentRow.Index).Value
MsgBox(data)
Cant seem to be able to fix it even by setting formatting to none. Any ideas or can you point me in right direction? Thank you in advance!

Related

convert text to single type

Dim fontsize As Single = CSng(SynopsisTSCmbFontSize.Text)
rtbSynopsis.Font = New Font(SynopsisTSCmbFonts.Text, fontsize)
to change the fontsize to the value selected in a combo box, the value has to be of the Single type.
the combobox is populated with numbers entered at the design mode, ranging from 7-78. I know that these are entered as strings.
the error is :
I have tried a number of things to convert the text (which are numbers, no letters) from the combobox to single to no avail. try parse did not work, trimming did not work, first convert to INT or DBL, then to SNG did not work.
What is the correct syntax here?
I would have thought that it was pretty standard stuff to change the fontsize.
I found a solution : instead of populating the combobox at design time, I populated it at runtime where I had full control over the type.
Dim i As Single
For i = 5 To 70
SynopsisTSCmbFontSize.Items.Add(i)
TreatmentTSCmbFontSize.Items.Add(i)
Next
once the comboboxes are correctly populated, I can run the rest of the code with no errors
thank you all for your time!

Return value of a point in a series in PowerPoint VBA

I need to return the value of a data point in a chart to compare it to a known value and display a data label if it is over a certain threshold in PowerPoint.
This post explains how to do it in excel, but .values doesn't appear to be in the ppt object model.
Determining the value of a point in Excel VBA
I know there is .points(i), but that doesn't seem to be able to return the actual value of the point.
Any help is appreciated.
Thanks,
Brian
This seems to work fine for me
Dim chartSeries As Series
Set chartSeries = chartShape.Chart.SeriesCollection(1)
seriesValue = chartSeries.Values(1)

Excel VBA: Get the right date into a cell using DatePicker

I have a UserForm with a DatePicker control in it.
It works fine, except when copying the selected date to the spreadsheet.
This is the code:
Range("A1").Value = UserForm1.DTPicker1.Value
Which returns:
00:00:00
In cell A1, no matter what date has been selected.
You cell formatting might be set to Time instead of Date.
Try changing that to see if it works.
Also, make formatting 'General' AFTER this step, to see if anything has been pasted in "A1".
You should need an intermediate variable to get it, like below:
t = Me.DTPicker1.Value
ws.Range("A1") = t
Make sure that the command to transfer the data is located in the same form or page of a multipage form as the DTPicker itself.
For some reason it wont work when the two are separated and will display a zero in the target cell. That zero is the "time" part of the date which has been switched off. Although the "Date" part refuses to transfer over, for some reason the time does, and so that zero time is read in the cell as time zero which is mid-day.
So in summary:
Keep the DTPicker and transfer control on the same page and that should solve the problem.
The code is pretty simple. It's
Sheet1.Range("AA9") = Me.DTPicker1.Value

Issue in getting the value from datagridview cell to put into decimal

This is my code for my button that will pop the value from the specific column.
dvList.Columns("Reg_Price").DefaultCellStyle.Format = "N2"
MsgBox(dvList.Rows(dvList.CurrentRow.Index).Cells.Item("Reg_Price").Value.ToString)
My value in the column "Reg_Price" is 0, when I click the button with the code above, the output is 0 also, I want the output to be 0.00, but the code above the msgbox is not working.
Thank you for the help.
The DefaultCellStyle.Format (and also cell format) operate only on the dataGridView display. When you get dvList.Rows(dvList.CurrentRow.Index).Cells.Item("Reg_Price").Value.ToString, you get the original cell, before formatting. You can use the vb.net Format function to format the numeric value for msgBox.

Getting display text as ###### for some of the cell in excel after writing from Vb.net code

I am writting to an excel file from my vb code. The code goes as below
xlsheet3 = xlBook.Sheets.Add(After:=xlSheet)
With xlsheet3
.Columns(5).NumberFormat = "#"
.Cells(j + 1, 5) = someStringValue 'Here "j" is a row counter and this line is in a "for loop"
end with
After writing to excel, most of the cells in excel are correct. But some of the cell's text comes as ####### however if I click on the cell, formula bar shows the correct result. I have tried giving single code before adding the text still that did not help.
Please help me in resolving this.
Thank you
There is not any issue with your code. You need to increase the width of the column or have to use word wrap. In excel if your value is not fully visible it shows it is "######".
If widening and wrapping text doesn't work and the format is set to text which allows display of only 255 characters, try changing the format to general.
This just indicates that the cell is too small for showing the result: make it wider.
See https://superuser.com/questions/65556/excel-displays-for-long-text-whats-wrong for some common reasons why Excel displays "######" in cells.
Either the cell is too narrow to display the contents or the contents are over 256 characters.
Check what you're writing to the cell. If it's not too long then all you need to do is resize the column to fit the new contents.
This is simply what Excel does when the data in a column is too wide to be displayed in the current column width. Make the column slightly wider and you will see all your data.
To autosize the column so it is wide enough to display all its data, double click the column divider at the right edge of the column, in the header bar.