Forums

Forums (http://www.abandonia.com/vbullet/index.php)
-   Programming (http://www.abandonia.com/vbullet/forumdisplay.php?f=25)
-   -   Slight Problem With My Code (http://www.abandonia.com/vbullet/showthread.php?t=14048)

JJXB 20-04-2007 03:39 AM

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.

jg007 21-04-2007 06:23 PM

<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!!!!





JJXB 22-04-2007 12:02 PM

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

Reup 22-04-2007 03:46 PM

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?

JJXB 23-04-2007 01:26 PM

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

Reup 23-04-2007 01:34 PM

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... :unsure:

jg007 23-04-2007 07:12 PM

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)


Reup 24-04-2007 06:30 AM

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).

jg007 24-04-2007 07:10 PM

<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)


JJXB 01-05-2007 10:46 PM

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


The current time is 06:34 PM (GMT)

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