公寓出租城市帮助 [英] Apartment Rental By City Help

查看:90
本文介绍了公寓出租城市帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<强> 1。应用程序首先打开信息的文本文件。该文件名为rental.txt,它列出了美国10个最昂贵城市的公寓租金中位数。

2。用户可以在显示的数据中选择一个城市,以查看该城市两居室公寓的中位数公寓费用。

3。当用户点击Compute Average Rental按钮时,将显示10个城市内的平均公寓租金。

4。 "文件"菜单显示"显示前十名城市和租赁费用","清除"和"退出"菜单项。

5。第二个Form对象显示Cities和Rental成本,并有一个重新打开初始Form对象的按钮。

使用两个Sub方法计算平均租赁成本。

我需要帮助才能完成此计划。这就是我到目前为止所拥有的。我不知道如何完成按钮的编码以及私人子计算所选城市的中位数成本。我无法弄清楚第二种形式的编码为
,我在第二种形式上几乎没有任何东西。如果有人能帮助我,那我们会很棒。谢谢。

I need help completing this program. This is what I have so far. I am not sure how to finish the coding for the button as well as the Private sub for calculating the median cost for the selected city. I can't figure out the coding for the second form as well, I hardly have anything on the second form. if someone could please help me out, that would we be great. Thank you.




选项严格打开¥b $ b $
Public Class frmApartmentRental

  &NBSP; '班级私人变量

  &NBSP; Public Shared _intSizeOfArray As Integer = 9

  &NBSP; Public Shared _strCityName(_intSizeOfArray)As String

  &NBSP; Private _decRentAmount(_intSizeOfArray)As Decimal



  &NBSP; Private Sub frmApartmentRental_Load(sender As Object,e As EventArgs)Handles MyBase.Load

  &NBSP; &NBSP; &NBSP; 'frmApartmentRental load事件读取租赁文本文件并填写为
  &NBSP; &NBSP; &NBSP; '包含租借物品的列表框对象。



  &NBSP; &NBSP; &NBSP; '初始化StreamReader对象的实例并声明变量。

  &NBSP; &NBSP; &NBSP; Dim objReader As IO.StreamReader

  &NBSP; &NBSP; &NBSP; Dim strLocationAndNameOfFile As String =" d:\rentals.txt"

  &NBSP; &NBSP; &NBSP; Dim intCount As Integer = 0

  &NBSP; &NBSP; &NBSP; Dim intFill As Integer

  &NBSP; &NBSP; &NBSP; Dim strFileError As String ="文件不可用。文件可用时重新启动。"
$


  &NBSP; &NBSP; &NBSP; '验证文件是否存在

  &NBSP; &NBSP; &NBSP;如果IO.File.Exists(strLocationAndNameOfFile)则为
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; objReader = IO.File.OpenText(strLocationAndNameOfFile)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; '逐行阅读文件,直到文件完成为止。
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;做objReader.Peek<> -1

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _strCityName(intCount)= objReader.ReadLine()

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; _decRentAmount(intCount)= Convert.ToDecimal(objReader.ReadLine())

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; intCount + = 1

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;循环

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; objReader.Close()



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 'ListBox对象填充了城市名称

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;对于intFill = 0 To(_strCityName.Length - 1)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; lstCity.Items.Add(_strCityName(intFill))

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;下一个

  &NBSP; &NBSP; &NBSP;否则

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MsgBox(strFileError ,," Error")

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;关闭()

  &NBSP; &NBSP; &NBSP;结束如果

  &NBSP;结束分


  &NBSP; Private Sub btnAverage_Click(sender As Object,e As EventArgs)处理btnAverage.Click

  &NBSP; &NBSP; &NBSP; '此事件处理程序计算10个城市内的平均公寓租金。

  &NBSP; &NBSP; &NBSP; '声明变量

  &NBSP; &NBSP; &NBSP; Dim intSelectedCity As Integer

  &NBSP; &NBSP; &NBSP; Dim strMissingSelection As String =" Missing Selection"

  &NBSP; &NBSP; &NBSP; Dim strSelectCityError As String =" Select a City"



  &NBSP;结束分


  &NBSP; Private Sub MakeObjectsVisible()

  &NBSP; &NBSP; &NBSP; '此程序显示显示结果的对象

  &NBSP; &NBSP; &NBSP; lblAverage.Visible = True

  &NBSP; &NBSP; &NBSP; lblCity.Visible = True

  &NBSP; &NBSP; &NBSP; lblMedian.Visible = True

  &NBSP; &NBSP; &NBSP; lstCity.Visible = True

  &NBSP;结束分


  &NBSP; Private Sub mnuDisplay_Click(sender As Object,e As EventArgs)处理mnuDisplay.Click

  &NBSP; &NBSP; &NBSP; 'mnuDisplay点击事件创建了一个frmCityRentals的实例

  &NBSP; &NBSP; &NBSP; Dim frmSecond As New frmCityRentals



  &NBSP; &NBSP; &NBSP; '隐藏此表单并显示城市租赁表格

  &NBSP; &NBSP; &NBSP;隐藏()

  &NBSP; &NBSP; &NBSP; frmSecond.ShowDialog()

  &NBSP;结束分


  &NBSP; Private Sub mnuClear_Click(sender As Object,e As EventArgs)处理mnuClear.Click

  &NBSP; &NBSP; &NBSP; 'mnuClear点击事件清除并重置表格

  &NBSP; &NBSP; &NBSP; lblCity.Visible = False

  &NBSP; &NBSP; &NBSP; lblMedian.Visible = False

  &NBSP; &NBSP; &NBSP; lblAverage.Visible = False

  &NBSP;结束分


  &NBSP; Private Sub mnuExit_Click(sender As Object,e As EventArgs)处理mnuExit.Click

  &NBSP; &NBSP; &NBSP; 'mnuExit点击事件关闭了申请

  &NBSP; &NBSP; &NBSP; Application.Exit()

  &NBSP;结束点¥
结束等级

Option Strict On

Public Class frmApartmentRental
    ' Class level private variables
    Public Shared _intSizeOfArray As Integer = 9
    Public Shared _strCityName(_intSizeOfArray) As String
    Private _decRentAmount(_intSizeOfArray) As Decimal

    Private Sub frmApartmentRental_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' The frmApartmentRental load event reads the rental text file and fills the
        ' Listbox object with the rental items.

        ' Intialize an instance of the StreamReader object and declare variables.
        Dim objReader As IO.StreamReader
        Dim strLocationAndNameOfFile As String = "d:\rentals.txt"
        Dim intCount As Integer = 0
        Dim intFill As Integer
        Dim strFileError As String = "The file is not available. Restart when the file is available."

        ' Verify the file exists
        If IO.File.Exists(strLocationAndNameOfFile) Then
            objReader = IO.File.OpenText(strLocationAndNameOfFile)
            ' Read the file line by line until the file is completed
            Do While objReader.Peek <> -1
                _strCityName(intCount) = objReader.ReadLine()
                _decRentAmount(intCount) = Convert.ToDecimal(objReader.ReadLine())
                intCount += 1
            Loop
            objReader.Close()

            ' The ListBox object is filled with the City Names
            For intFill = 0 To (_strCityName.Length - 1)
                lstCity.Items.Add(_strCityName(intFill))
            Next
        Else
            MsgBox(strFileError, , "Error")
            Close()
        End If
    End Sub

    Private Sub btnAverage_Click(sender As Object, e As EventArgs) Handles btnAverage.Click
        ' This event handler calculates the average apartment rental within the 10 cities.
        ' Declare variables
        Dim intSelectedCity As Integer
        Dim strMissingSelection As String = "Missing Selection"
        Dim strSelectCityError As String = "Select a City"

    End Sub

    Private Sub MakeObjectsVisible()
        ' This procedure displays the objects showing the results
        lblAverage.Visible = True
        lblCity.Visible = True
        lblMedian.Visible = True
        lstCity.Visible = True
    End Sub

    Private Sub mnuDisplay_Click(sender As Object, e As EventArgs) Handles mnuDisplay.Click
        ' The mnuDisplay click event creates an instance of the frmCityRentals
        Dim frmSecond As New frmCityRentals

        ' Hide this form and show the City Rentals form
        Hide()
        frmSecond.ShowDialog()
    End Sub

    Private Sub mnuClear_Click(sender As Object, e As EventArgs) Handles mnuClear.Click
        ' The mnuClear click event clears and resets the form
        lblCity.Visible = False
        lblMedian.Visible = False
        lblAverage.Visible = False
    End Sub

    Private Sub mnuExit_Click(sender As Object, e As EventArgs) Handles mnuExit.Click
        ' The mnuExit click event closes the application
        Application.Exit()
    End Sub
End Class

推荐答案

Kidlowe13,

Hi Kidlowe13,

欢迎来到MSDN论坛。

Welcome to the MSDN forum.

请参阅您的说明,您的问题与Windows窗体开发有关。由于我们的论坛是讨论VS IDE,我将帮助您将此主题移至相应的论坛以获得更好的支持,感谢您的理解。

Refer to your description, your issue is about the Windows Forms development. Since our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum for a better support, thank you for your understanding.

致以最诚挚的问候,

Sara


这篇关于公寓出租城市帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆