Results 1 to 10 of 10

Thread: [2005] Reading Strings from excel sheet (Characterwise) ??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Question [2005] Reading Strings from excel sheet (Characterwise) ??

    hey guys!

    I need to write a code which will read sentences from a specific column in a specified excel sheet.

    But I need to store each character in the sentence separately (including space), maybe in an array. I dun rilli know how to go about doing this.

    Please Advise


    cheers
    Abhilash

    P.S : I need these characters to be later compared with another excel table to get their dimensions.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Use the Characters object. Its off of the Range object.

    Range.Characters.Count


    Range.Characters(Start:=1, Length:=x)

    etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Hey RobDog!

    I used the Characters Object as you suggested but i am facing a problem. I need to store each character in a range of excel cells separately in an array. I am using a Char array but am getting a InvalidCastException


    Conversion from type 'Characters' to type 'Char' is not valid.

    the affected code is below.


    Code:
    For x = 23 To 33 Step 1
                n = oSheet1.Range("A" & x).Characters.Count
                Dim ActualChar(n - 1) As Char
                Dim CharLength(n - 1) As Integer
                For y = 0 To n - 1 Step 1
                    ActualChar(y) = oSheet1.Range("A" & x).Characters(y + 1, 1)

    The error occurs on the last line of the shown code.



    Please advise


    Cheers
    Abhilash

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Why not define ActualChar as a string Array instead?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    I tried that also.. it doesnt work.. same error

    Code:
    Conversion from type 'Characters' to type 'String' is not valid.
    I really need to sort this out.. your help will be greatly appreciated..

    cheers
    Abhilash

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Dim ActualChar(n - 1) As String

    ActualChar(y) = oSheet1.Range("A" & x).Characters(y + 1, 1).ToString()
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Member
    Join Date
    Mar 2007
    Posts
    32

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Here is a great tutorial on working with strings in VB: http://www.vbexplorer.com/VBExplorer...tutorial_3.asp
    I'd say you can use the split command.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Hey Rob!

    I tried wad u suggested.. it works as in the error doesnt show anymore.. but the value assigned to the variable at the end of the command is some funny statement.

    Code:
    ActualChar(y) = oSheet1.Range("A" & x).Characters(y + 1, 1).ToString()
    When i checked the value stored in ActualChar(y) after this statement.. it came out to be something like "System.__ComObject" which is not wads is in the excel sheet.

    I Read the tutorial link provided and will try and use some of the commands thr.. it rilli is very useful.. thx mate...


    cheers
    Abhilash

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    Sorry, didnt verify in the IDE just typed it. The Characters is not a collection but rather an Object. So you may need to CType it to a String type instead.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] Reading Strings from excel sheet (Characterwise) ??

    I tried Ctype, but it gives the same problem.. i then tried Mid$ command and it works just fine..

    cheers
    abhilash

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width