Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Search Today's Posts Mark Forums Read
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 20-04-2007, 04:39 AM   #1
JJXB
Pi-voh
 
JJXB's Avatar

 
Join Date: Oct 2004
Location: Godmanchester, England
Posts: 850
Default

I'm Learning how to code in Visual Basic (with VB Express 2005) and i'm trying to code A ZDoom Frontend but i'm stumbling upon problems with getting the filename for the PWAD's that people might want to use in the command line. here's the little bit of code that's the problem:
Code:
********Dim WAD As System.Type
********If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
************TextBox3 = WAD(OpenFileDialog1.OpenFile())
********End If
it comes up with the error:
"Class 'System.Type' cannot be indexed because it has no default property."
now i'm not sure why this is happening but please keep in mind that i've only just started learning how to code and i'm managing to get my head around the logic behind most of what i have seen so far but i can't figure some things out.
__________________
~Ceramic White PSP Status~
FW: 5.00 M33-6
Memory Stick: 8gb
JJXB is offline                         Send a private message to JJXB
Reply With Quote
Old 21-04-2007, 07:23 PM   #2
jg007
Super Freak
 
jg007's Avatar

 
Join Date: Feb 2007
Location: Peterlee, England
Posts: 169
Default

<div class='quotetop'>QUOTE(JJXB @ Apr 20 2007, 04:39 AM) [snapback]287605[/snapback]</div>
Quote:
I'm Learning how to code in Visual Basic (with VB Express 2005) and i'm trying to code A ZDoom Frontend but i'm stumbling upon problems with getting the filename for the PWAD's that people might want to use in the command line. here's the little bit of code that's the problem:
Code:
********Dim WAD As System.Type
********If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
************TextBox3 = WAD(OpenFileDialog1.OpenFile())
********End If
it comes up with the error:
"Class 'System.Type' cannot be indexed because it has no default property."
now i'm not sure why this is happening but please keep in mind that i've only just started learning how to code and i'm managing to get my head around the logic behind most of what i have seen so far but i can't figure some things out.
[/b]
I'm afraid don't know all that much about VB as I tend to learn it as and when I require it and tend to use it more in excel than anything else also I have just reformatted so have wiped VB and will have to reload it at some point but I was wondering why you were defining WAD as that particular type -

Dim WAD As System.Type

as stated my VB is a 'bit' lousy at times but will a string variable type not do for that value? , i'm not really sure what you are trying to define this as so appologies if this is totally incorrect!!!!




jg007 is offline                         Send a private message to jg007
Reply With Quote
Old 22-04-2007, 01:02 PM   #3
JJXB
Pi-voh
 
JJXB's Avatar

 
Join Date: Oct 2004
Location: Godmanchester, England
Posts: 850
Default

setting it as a string gives me a different error completely, i'm not in VB at the sec so i can't tell you it at the sec
__________________
~Ceramic White PSP Status~
FW: 5.00 M33-6
Memory Stick: 8gb
JJXB is offline                         Send a private message to JJXB
Reply With Quote
Old 22-04-2007, 04:46 PM   #4
Reup
10 GOSUB Abandonia
20 GOTO 10
 
Reup's Avatar

 
Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
Default

Use the following code (I'm a C# guy, so I'm not sure if the VB syntax is correct... I more or less HATE VB syntax :P):

Code:
Dim openFileDialog1 as OpenFileDialog
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
******TextBox3.Text = Path.GetFileName( openFileDialog1.FileName )
Whats going on is that you ask the OpenFileDialog to return the complete system path of the selected file and use the static System.IO.Path function parse the FileName for you. Then you set the Text property of the textbox to this.

Your code tried to do quite a lot of other things. By leaving out the .Text, you're trying to set the TextBox object directly instead of its Text property. And, what you think an object of type Type is exactly?
Reup is offline                         Send a private message to Reup
Reply With Quote
Old 23-04-2007, 02:26 PM   #5
JJXB
Pi-voh
 
JJXB's Avatar

 
Join Date: Oct 2004
Location: Godmanchester, England
Posts: 850
Default

i've looked at the code and tried adapting it so it now looks like this (the full block of code now, not just the problem bit)
Code:
********Dim OpenFileDialog1 As New OpenFileDialog()
********OpenFileDialog1.Filter = "Wad Files|*.WAD"
********OpenFileDialog1.Title = "Select The WAD You Wish To Add"
********
********Dim TextBox3 As TextBox
********If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
************TextBox3.Text = Path.GetFileName(OpenFileDialog1.FileName)
********End If
and it's coming up with:
Quote:
Name 'Path' is not declared[/b]
and i'm not sure how to proceed since i'm not sure what to declare "Path" as
__________________
~Ceramic White PSP Status~
FW: 5.00 M33-6
Memory Stick: 8gb
JJXB is offline                         Send a private message to JJXB
Reply With Quote
Old 23-04-2007, 02:34 PM   #6
Reup
10 GOSUB Abandonia
20 GOTO 10
 
Reup's Avatar

 
Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
Default

Mm... I copied this more or less from my C# file, which compiled and ran without errors... Did you add the System.IO namespace to you Imports?
The thing is, that you never have to declare Path, since its a Static class and can't be instantiated...
Reup is offline                         Send a private message to Reup
Reply With Quote
Old 23-04-2007, 08:12 PM   #7
jg007
Super Freak
 
jg007's Avatar

 
Join Date: Feb 2007
Location: Peterlee, England
Posts: 169
Default

I have used this and it seems to work but it gives the full filepath and the only way I could chop it up was a very awkward use of mid!

Code:
**OpenFileDialog1.Filter = "Wad Files|*.WAD"
********OpenFileDialog1.Title = "Select The WAD You Wish To Add"
********Dim WAD As String
********If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
************WAD = (OpenFileDialog1.FileName)
jg007 is offline                         Send a private message to jg007
Reply With Quote
Old 24-04-2007, 07:30 AM   #8
Reup
10 GOSUB Abandonia
20 GOTO 10
 
Reup's Avatar

 
Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
Default

That's what the Path-class takes care of. You know Path.GetFileName of Path.GetFileNameWithoutExtension etc. Check out the full range @ http://msdn2.microsoft.com/en-us/library/s...ers(vs.71).aspx
(this is .NET 1.1 version, since I don't know against which framework you're programming).
Reup is offline                         Send a private message to Reup
Reply With Quote
Old 24-04-2007, 08:10 PM   #9
jg007
Super Freak
 
jg007's Avatar

 
Join Date: Feb 2007
Location: Peterlee, England
Posts: 169
Default

<div class='quotetop'>QUOTE(Reup @ Apr 24 2007, 07:30 AM) [snapback]288251[/snapback]</div>
Quote:
That's what the Path-class takes care of. You know Path.GetFileName of Path.GetFileNameWithoutExtension etc. Check out the full range @ http://msdn2.microsoft.com/en-us/library/s...ers(vs.71).aspx
(this is .NET 1.1 version, since I don't know against which framework you're programming).
[/b]

doh!, i have never really used VB to this level but finally managed a working code, although it is not quite as yours seems to be it seems to work -

(Visual Basic Express 2005 )

Code:
Dim WAD As System.IO.FileInfo

OpenFileDialog1.Filter = "Wad Files|*.*"
********OpenFileDialog1.Title = "Select The WAD You Wish To Add"
********If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
************WAD = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName)
************MsgBox(WAD.Name)
************MsgBox(WAD.DirectoryName)
jg007 is offline                         Send a private message to jg007
Reply With Quote
Old 01-05-2007, 11:46 PM   #10
JJXB
Pi-voh
 
JJXB's Avatar

 
Join Date: Oct 2004
Location: Godmanchester, England
Posts: 850
Default

just got round to trying it and it works a treat plus i adapted the code to
Code:
Dim WAD As System.IO.FileInfo

OpenFileDialog1.Filter = "PWAD Files|*.WAD"
********OpenFileDialog1.Title = "Select The WAD You Wish To Add"
********If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
************WAD = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName)
************TextBox1.Text = WAD.Name
End IF
And it had the desired effect
__________________
~Ceramic White PSP Status~
FW: 5.00 M33-6
Memory Stick: 8gb
JJXB is offline                         Send a private message to JJXB
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
A slight (resolution-related) DOSBox problem. Simoneer Tech Corner 13 31-05-2009 04:53 PM
Slight Delay When I Run Cd-rom Games, Why? Razors78 Troubleshooting 8 31-05-2007 04:58 PM
Slight Problem. Please help.ASAP!!!! Anonymous Troubleshooting 5 17-07-2004 02:36 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 04:31 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.