|
-
Apr 16th, 2007, 01:59 AM
#1
Thread Starter
Member
[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.
-
Apr 16th, 2007, 03:29 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 18th, 2007, 01:44 AM
#3
Thread Starter
Member
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
-
Apr 18th, 2007, 03:33 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 18th, 2007, 03:48 AM
#5
Thread Starter
Member
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
-
Apr 18th, 2007, 04:02 AM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 18th, 2007, 09:38 AM
#7
Member
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.
-
Apr 19th, 2007, 03:14 AM
#8
Thread Starter
Member
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
-
Apr 19th, 2007, 04:01 AM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 23rd, 2007, 02:35 AM
#10
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|