1>c:\users\black chocobo\desktop\wavemachine\managesongs\wavemachine\wavemachine\wavemachine\Form1.h(334) : error C3845: 'WaveMachine::Form1::filePath': only static data members can be initialized inside a ref class or value type

// the actual music file and its path is kept in the second subItem (of each track)
			 String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

Any suggestions

Post some of the surrounding code for this one. You're trying to initialize something within a class declaration or struct.

You didn't post enough code for me to be sure, but from the error I'd guess filePath is a data member and you're doing something like this:

ref class Form1 {
    String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

    // ...
};

C++ doesn't work like that though, you want to do non-default initialization from the constructor in most cases:

ref class Form1 {
    String^ filePath;

    // ...
public:
    Form1()
        : filePath("some value")
    {}

    // ...
};

Though since you're trying to use the Text property of a control, you'll likely need to wait until after the controls have been fully initialized. A good time to do this is in the form's Load event:

void Form1_Load(Object^ sender, EventArgs^ e)
{
    filePath = listView1->CheckedItems[0]->SubItems[2]->Text;
}

I half understood you.

This particular error is within a play button command.

private: System::Void playBtn_Click(System::Object^  sender, System::EventArgs^  e) {

			
			 // Tian: for this example, I restrict the selection and playing of one track only. You can make it more flexible
		 	 if(this->listView1->CheckedItems->Count != 1) {
				 MessageBox::Show("Please check one of tracks from the list below to play!");
				 return;
			
			 //axWindowsMediaPlayer1->Ctlcontrols->next();
			 int random;
				Random^ rand;
				rand = gcnew Random();
				int count = axWindowsMediaPlayer1->mediaCollection->getAll()->count;
				random = rand->Next(count);
				axWindowsMediaPlayer1->currentMedia = axWindowsMediaPlayer1->mediaCollection->getAll()->Item[random];
				axWindowsMediaPlayer1->Ctlcontrols->play();
		 }
			 }

			 // the actual music file and its path is kept in the second subItem (of each track)
			 String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

			 // using soundplayer class to play the sound
			 // note that it can play .wav sound only, and this .wav file must be in PCM (pulse-code modulation) or exception will occur
			 // for this assignment, you may want to choose some of .wav music track to demonstrate 
			SoundPlayer^ player = gcnew SoundPlayer();
			player->SoundLocation = filePath;
			player->Play();

		 }
};
}

as for the non-default initialization:

#pragma endregion
	#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
			 {
				 // Tian: open and parse the file while the form is being loaded
				 // pls. note that you need double '\' for the path
				 // you need to edit the path accordingly when compiling in your PC
				String^ fileToRead = "C:\\Users\\Black Chocobo\\Desktop\\WaveMachine\\TrackListing.txt";
				StreamReader^ objReader = gcnew StreamReader(fileToRead);

				// Tian: split the tracks in the tracks into substring using delimiters ','
				array<Char>^chars = {','};
				IEnumerator^ myEnum;
				String^ line;
				array<String^>^ split;
				ListViewItem^ item;

				while (!objReader->EndOfStream)
				{
					line = objReader->ReadLine();
					split = line->Split( chars );
					myEnum = split->GetEnumerator();
					while ( myEnum->MoveNext() )
					{
						// fill the first column
						String^ text = safe_cast<String^>(myEnum->Current)->Trim();
						if (text == "") break;

						item = gcnew ListViewItem(text);
					
						// fill the second and third column (subItem)
						for (int j=0; j<2; j++) 
						{
							if (myEnum->MoveNext())
							{
								text = safe_cast<String^>(myEnum->Current)->Trim();
								item->SubItems->Add(text);
							}
						}

						// add to the listView
						this->listView1->Items->Add(item);
					}
				}

				// close the file
				objReader->Close();
			}

This particular error is within a play button command.

No, it's not. Count your braces and you'll see that filePath is defined outside of playBtn_Click. Or you could properly format your code to begin with and this would be immediately obvious.

I have double checked my braces and from what I can see, they are fine?

Sorry if you can see otherwise Can you specifically point them out?

I have just double checked with a working reference. ( Given from my software programming teacher that never replies )

This is your code with better formatting:

System::Void playBtn_Click(System::Object^  sender, System::EventArgs^  e) 
{
    // Tian: for this example, I restrict the selection and playing of one track only. You can make it more flexible
    if(this->listView1->CheckedItems->Count != 1) {
        MessageBox::Show("Please check one of tracks from the list below to play!");
        return;

        //axWindowsMediaPlayer1->Ctlcontrols->next();
        int random;
        Random^ rand;
        rand = gcnew Random();
        int count = axWindowsMediaPlayer1->mediaCollection->getAll()->count;
        random = rand->Next(count);
        axWindowsMediaPlayer1->currentMedia = axWindowsMediaPlayer1->mediaCollection->getAll()->Item[random];
        axWindowsMediaPlayer1->Ctlcontrols->play();
    }
}

// the actual music file and its path is kept in the second subItem (of each track)
String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

I edited my post to how it was meant to be... Sorry if it appeared as if the braces were missing

Now you have a brace mismatch. At this point I'm going to stop helping unless you post a more complete example. Remove as much unnecessary code as you can and post the smallest complete code that exhibits your error.

ok gimmie a sec

brace mismatch ? where? From what I can see my errors are on these lines:

String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

and

SoundPlayer^ player = gcnew SoundPlayer();

They are within play button :

private: System::Void playBtn_Click(System::Object^  sender, System::EventArgs^  e) 
		 {

			
			 // Tian: for this example, I restrict the selection and playing of one track only. You can make it more flexible
		 	 if(this->listView1->CheckedItems->Count != 1) {
				 MessageBox::Show("Please check one of tracks from the list below to play!");
				 return;
			
			 //axWindowsMediaPlayer1->Ctlcontrols->next();
			 int random;
				Random^ rand;
				rand = gcnew Random();
				int count = axWindowsMediaPlayer1->mediaCollection->getAll()->count;
				random = rand->Next(count);
				axWindowsMediaPlayer1->currentMedia = axWindowsMediaPlayer1->mediaCollection->getAll()->Item[random];
				axWindowsMediaPlayer1->Ctlcontrols->play();
		 }
			 }

			 // the actual music file and its path is kept in the second subItem (of each track)
			 String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

			 // using soundplayer class to play the sound
			 // note that it can play .wav sound only, and this .wav file must be in PCM (pulse-code modulation) or exception will occur
			 // for this assignment, you may want to choose some of .wav music track to demonstrate 
			SoundPlayer^ player = gcnew SoundPlayer();
			player->SoundLocation = filePath;
			player->Play();

		 }
};
}

I have checked line for line, something is obviously wrong but Im only beginner so am asking for all the help I can get, The mismatch braces I cannot see

As Narue was explaining:


They are not within the play button :

private: System::Void playBtn_Click(System::Object^  sender, System::EventArgs^  e) 
		 {

			
			 // Tian: for this example, I restrict the selection and playing of one track only. You can make it more flexible
		 	 if(this->listView1->CheckedItems->Count != 1) {
				 MessageBox::Show("Please check one of tracks from the list below to play!");
				 return;
			
			 //axWindowsMediaPlayer1->Ctlcontrols->next();
			 int random;
				Random^ rand;
				rand = gcnew Random();
				int count = axWindowsMediaPlayer1->mediaCollection->getAll()->count;
				random = rand->Next(count);
				axWindowsMediaPlayer1->currentMedia = axWindowsMediaPlayer1->mediaCollection->getAll()->Item[random];
				axWindowsMediaPlayer1->Ctlcontrols->play();
		         } //IF ENDS HERE
	        } //System::Void playBtn_Click ENDS HERE

//Everything below here is [B]outside[/B] of the playBtn_Click method (where it should not be)			 

// the actual music file and its path is kept in the second subItem (of each track)
			 String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

			 // using soundplayer class to play the sound
			 // note that it can play .wav sound only, and this .wav file must be in PCM (pulse-code modulation) or exception will occur
			 // for this assignment, you may want to choose some of .wav music track to demonstrate 
			SoundPlayer^ player = gcnew SoundPlayer();
			player->SoundLocation = filePath;
			player->Play();

		 }
};
}

this is odd because removing them makes me go from 26 errors to 18 so something still cannot be right?

Also the working reference is coded in the above manner

Move your brace from line 18 (in the last listing you posted) up to line 9, I think you wanted to close the if statement there.

Delete the one on line 19. The brace on line 32 marks the end of the class. Verify all of your pairs in between the opening one at the top of the class and that one on 32 and make sure they match up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.