Click here to Skip to main content
15,891,253 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionProblem with catching exceptions Pin
Badmafia21-Mar-09 14:57
Badmafia21-Mar-09 14:57 
AnswerRe: Problem with catching exceptions Pin
nlarson1121-Mar-09 15:45
nlarson1121-Mar-09 15:45 
AnswerRe: Problem with catching exceptions Pin
George B Gilbert21-Mar-09 16:45
George B Gilbert21-Mar-09 16:45 
QuestionHow could you select an item in listview from a different tabpage? Pin
JUNEYT21-Mar-09 13:48
JUNEYT21-Mar-09 13:48 
AnswerRe: How could you select an item in listview from a different tabpage? Pin
George B Gilbert21-Mar-09 17:41
George B Gilbert21-Mar-09 17:41 
GeneralRe: How could you select an item in listview from a different tabpage? Pin
JUNEYT22-Mar-09 0:51
JUNEYT22-Mar-09 0:51 
GeneralRe: How could you select an item in listview from a different tabpage? Pin
George B Gilbert22-Mar-09 5:22
George B Gilbert22-Mar-09 5:22 
QuestionWriting an Excel table to a DataTable / The values from Excel-cells with "date"-format are not assumed Pin
TheSolid21-Mar-09 3:19
TheSolid21-Mar-09 3:19 
Hi,

I want to read a cell-value from an Excel-worksheet in VB.NET 2005 with the following function:

Private Function strCellValue(ByVal strFilname As String, ByVal strWorksheet As String, ByVal strCell As String) As String

  Dim dtDataTable As New DataTable
  Dim dbConnection As OleDb.OleDbConnection
  Dim dbDataAdapter As OleDb.OleDbDataAdapter
  dbConnection = New OleDb.OleDbConnection
  dbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=" & strFilename & ";" & "Extended Properties='Excel 8.0;HDR=NO'"
  dbConnection.Open()
  dbDataAdapter = New OleDb.OleDbDataAdapter("Select * From " & "[" & strWorksheet & "$]", dbConnection)
  dbDataAdapter.Fill(dtDataTable)
  strCellValue = dtDataTable.Rows(intRow(strCell)).Item(intColumn(strCell)).ToString
  dbConnection.Close()

End Function

with
Private Function intRow(ByVal strCell As String) As Integer

  intRow = CInt(System.Text.RegularExpressions.Regex.Replace(strCell, "[A-Z]", "")) - 1

End Function

and
Private Function intColumn(ByVal strCell As String) As Integer

    Dim intI As Integer
    Dim strColumn As String

    strColumn = System.Text.RegularExpressions.Regex.Replace(strCell, "[0-9]", "")
    intColumn = 0
    For intI = 0 To strColumn.Length - 1
      intColumn += (Asc(Mid(strColumn, strColumn.Length - intI, 1)) - 64) * CInt(Math.Pow(26, intI))
    Next
    intColumn -= 1

  End Function


The last 2 functions converts only the "cell-address" in Excel (e.g. "C4") to the column and row for the data-table (e.g. C==2 and 4==3).

Problem: If a cell-value in Excel is formated as date and the value in this cell is not a date (e.g. the string "Hello"), the value is assumed correct, means strCellValue="Hello". If the value is a number and so, the cell-value is a valid date (e.g. "2009.03.21"), an empty string is assumed, means strCellValue=""


Any idea why? Thank you very much.
Christian
AnswerSolved: Writing an Excel table to a DataTable / The values from Excel-cells with "date"-format are not assumed [modified] Pin
TheSolid21-Mar-09 21:56
TheSolid21-Mar-09 21:56 
Questionabout MDI child form. Pin
p_m_kanthi21-Mar-09 3:03
p_m_kanthi21-Mar-09 3:03 
AnswerRe: about MDI child form. Pin
DaveAuld21-Mar-09 3:20
professionalDaveAuld21-Mar-09 3:20 
AnswerRe: about MDI child form. Pin
nazimghori21-Mar-09 7:56
nazimghori21-Mar-09 7:56 
QuestionProblem with check box Pin
nazimghori21-Mar-09 2:57
nazimghori21-Mar-09 2:57 
AnswerRe: Problem with check box Pin
DaveAuld21-Mar-09 3:38
professionalDaveAuld21-Mar-09 3:38 
GeneralRe: Problem with check box Pin
nazimghori21-Mar-09 4:05
nazimghori21-Mar-09 4:05 
AnswerRe: Problem with check box Pin
tech60321-Mar-09 5:52
tech60321-Mar-09 5:52 
GeneralRe: Problem with check box Pin
DaveAuld21-Mar-09 6:25
professionalDaveAuld21-Mar-09 6:25 
GeneralRe: Problem with check box Pin
nazimghori21-Mar-09 7:50
nazimghori21-Mar-09 7:50 
QuestionRe: Problem with check box Pin
nazimghori21-Mar-09 7:59
nazimghori21-Mar-09 7:59 
AnswerRe: Problem with check box Pin
DaveAuld21-Mar-09 11:05
professionalDaveAuld21-Mar-09 11:05 
QuestionRe: Problem with check box Pin
nazimghori21-Mar-09 18:23
nazimghori21-Mar-09 18:23 
AnswerRe: Problem with check box [modified] Pin
DaveAuld21-Mar-09 21:54
professionalDaveAuld21-Mar-09 21:54 
QuestionRe: Problem with check box Pin
nazimghori21-Mar-09 22:58
nazimghori21-Mar-09 22:58 
QuestionRe: Problem with check box Pin
nazimghori21-Mar-09 23:11
nazimghori21-Mar-09 23:11 
AnswerRe: Problem with check box Pin
DaveAuld21-Mar-09 23:52
professionalDaveAuld21-Mar-09 23:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.